zlacker

[parent] [thread] 2 comments
1. NightM+(OP)[view] [source] 2019-11-11 09:37:16
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-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.

replies(2): >>FabHK+X5 >>gpdere+lr
2. FabHK+X5[view] [source] 2019-11-11 10:47:53
>>NightM+(OP)
That link has a very insightful discussion (and incidentally provides a nice fast correct solution, and use case, for the initial problem!).
3. gpdere+lr[view] [source] 2019-11-11 14:23:39
>>NightM+(OP)
Probably 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.
[go to top]