only 2 test cases passed.
other 3 showing tle.
any optimization will highly appreaciated. please figure out.
Simple Enough Problem
Your code is failing large test cases.
Test cases of range long long int.
Also the solve function though logically seems fine is leading to runtime error in large test case. And the cause of runtime error is that the code is not proceeding further.
i tried as long long int but it still showing tle.
let me know if you have any other approach.
This is one approach you can look into:
There is some runtime error incurred in large test cases due to which the code execution does not proceed.
can you please explain your approach ?
In this approach, we take into consideration that N/2 will eventually reduce to 0 or 1. Therefore for every N we are finally reducing our calculations to N%2, and hence this leads us to the conditional return statements.
Since the function execution is symmetrical in the order N/2, N%2, N/2
N%2 is always in the mid of the sequence for every N.
In the very beginning we have calculated the total length of sequence to determine initial length of the sequence.
I hope this helps you get the gist of the approach.
awesome explanation.
Got it.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.