Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. The following code sums the digits in a number. What is its big O time?
  2. ```c++
  3. int sumDigits(int n) {
  4. int sum = 0;
  5. while (n > 0) {
  6. sum += n % 10;
  7. n /= 10;
  8. }
  9. return sum;
  10. }
  11. ```
  12.  
  13. My answer was that due to the while loop this function has a complexity of O(n), however the feedback that I received was
  14. "Would you like to reconsider your answer? Make sure you specify the time in n where n is the input number."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement