I got partially correct answer in KCHAR.
Link to the Question : KCHAR
Link to my solution : link
Please point out my mistake and try to debug my code. Also, as I am getting correct answer in small input size, have I made any mistakes in data types? Please clarify my doubts.
Thank you :slight_smile:

EDIT : Got AC. Thanks to @abhikalpu_123 and @raj79 for help. Appreciate it! Thanks!

its quite tough to debug someone’s code , can u say what have you done , then it will b easy to read through your code :slight_smile:

1 Like

Ya I know, Thanks! Well I found a pattern for all indexes. All even index(say k) have same character as their (better) halves :stuck_out_tongue: (i.e k/2). Now for odd index, the character at odd index is different from the difference of character at the next greatest power of 2 and the index(i.e p(power of 2>k) - k). And then I ran a recursive function to find the answer.

I know I am bad at explaining but I tried my best!!

The max value of K can be up to 10^18 But your code is handling up to 2^59 i.e. 5*10^17. In your above code make increase the length of array a to 61 instead of 60. (and corresponding changes like making every for loop i<61). As @raj97 said its quite tough but im in a vaccation :smiley:

1 Like

Or simply, find and replace 61 by 60. :stuck_out_tongue:

i guess you are complicating things enough in your code , and this will not be running for 10e18 as @abhikalpu_123 said. your logic is right , but it fails at higher values. while(n%2==0) n/=2; if (n%4==1) print a else print c, it was as simple as that , an overview of your logic actually. i did the same as your logic , but in a normal while loop. this will eazily run , just use long long int

Thanks for analysis of the code :slight_smile: Urghh when will I stop making small mistakes!

Thanks for the help man… Appreciate it :slight_smile:

I just had a array 1 size smaller as @abhikalpu_123 pointed out!! Got AC now… Thanks for the help though :slight_smile: