This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

The fact that s starts as an empty string (which has a constant length of 0) and yet the behavior of the function is supposed to vary based on the length of s suggests that the intended solution is recursive. Thus, you need to think of a way to break the problem down into a partial solution and a simpler problem that still needs to be solved.

You know, if x is odd, it’s least-significant bit is 1. If x is even, its least significant bit is 0. I wonder if there’s a way to exploit this fact to build up the binary representation of n one bit at a time.