We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Separate the Numbers
- Discussions
Separate the Numbers
Separate the Numbers
Sort by
recency
|
104 Discussions
|
Please Login in order to post a comment
c++
If you understand the main idea behind this problem, then the solution is easy. We have to figure out two things:
Algo:
Iterate through the string and try every possible starting number by taking its prefix.
Now simulate building the sequence by adding next numbers:
Finally, check if the built string matches the original:
If no such starting number worked, then the string isn’t beautiful:
print("NO")
I spent like 10 hours trying to do this the hard way. When I figured out the easy way I did it in 5 minutes during a business meeting. Do yourself a favor:
For input "99100", grab the first digit 9 and build beautiful string 91011, and check whether it's identical to 99100, It's not. So grab the first 2 digits 99 and build beautiful string 99100. It's identical, so "YES 99".
Don't try to stairstep a left index and a right index or dynamically keep track of curernt index length or anything. Save it for the harder questions lmao.
I have no clue in whos vocab is this a Basic - Easy questions. This is more like a medium question and I would say a harder one of that.
I have used a backtracking kind approach. Try diff length numbers to begin the recursive calls, then check if the next number we can come up with is +1 of previous. If we find a number like that we have another recursive call.| If the number is too big we can stop and return false. If the starting number size is already more than half the digits count we can also stop.