3 ms·
This particular problem (number of digits in a number) is actually monumentally important for performance reasons for e.g. json generation. See https://m.facebo
by NightMKoder 7y ago
This particular problem (number of digits in a number) is actually monumentally important for performance reasons for e.g. json generation. See https://m.facebook.com/notes/facebook-engineering/three-optimization-tips-for-c/10151361643253920/ https://m.facebook.com/notes/facebook-engineering/three-opti... for details.
That said, I do agree that as stated the problem is a toy. The problem statement could at least motivate the lack of string operations - i.e. pretend you’re the language designer and you’re tasked with implementing str(int) in C. Just saying “don’t do that” isn’t helpful. Gaining an understanding that nothing is magical is useful though.
- FabHK 7y agoThat link has a very insightful discussion (and incidentally provides a nice fast correct solution, and use case, for the initial problem!).
- gpderetta 7y agoProbably the students do not know about big O notation at this point, but requiring a solution that uses at most O(1) additional space would be enough. Then again, automatic bignums in python make it hard to evaluate the space complexity.