algoram
BAN USER
Questions (1)
Comments (3)
Reputation 110
- 2of 2 votes
AnswersU have a number, don't know how long it is, do not know how many digits, don't know when number ends, do not know which is the last number. There is a function to increment the number by 1, but function can take only stream of digits and not the complete number e.g if you have 878999 as a number, you could input this number into the function only as single digit e.g 8,7,8,9,9,9. The output should be the whole number incremented by 1 i.e 879000, remember only single digits you can send to function as input. You can use any data structure, but need to tell why you are using that particular data structure. No need to worry about Time complexity.
- algoram in United States for Site Reliability Engineering Team
Kindly, suggest how to approach this problem ?| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Yes ! Several Good Points made, the previous digit, present present digit and next digit should be kept track of. Have a condition to check for the last digit in the stream. Digit 9 in anywhere is a special case, what if we end up with number 9999999999999999, traversing all the way to the first digit and then back to unit place would end up with O(n+n).
- algoram November 30, 2012Would any kind of tree or hashing help in solving ?