Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The following code sums the digits in a number. What is its big O time?
- ```c++
- int sumDigits(int n) {
- int sum = 0;
- while (n > 0) {
- sum += n % 10;
- n /= 10;
- }
- return sum;
- }
- ```
- My answer was that due to the while loop this function has a complexity of O(n), however the feedback that I received was
- "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