Codenation

I did 1, 2 and got stuck on 4/15 on 3rd one. Throughout the challenge I felt that I was close to the solution, but wasn’t to be…

how to proceed further bro?

@rituraj22 Can you plz tell me the solution for 2nd problem .I am got confused by this line “You need to obtain the largest string of even length and the difference between the index of first and last digit should be minimum possible”.
We need a even length string with largest length so why we not do like just to make all odd frequency into even frequency and thats it. Because we need to find the largest even length…I really didnt get it why it is wrong. Please anyone.

Yes , it’s ans is 5…

can you please explain your approach or send the solution?

For which question?

first question …

I compared the value it outputs to my program for entire range 1 to 10^7 and I can’t find any case where my solution is wrong. HIxUO0 - Online C++ Compiler & Debugging Tool - Ideone.com

Any help would be appreciated.

we can solve last question using manacher algorithm, and building segment tree with max idx and min idx on this d1 array(refer link), so if two ranges overlap,like at idx 2 u are getting 6 length and idx 8 and idx 10 you are getting 8 length of radius you could say of palindrome then obviously you will prefer at idx 10 and chose radius accordingly of both,that could give max product.you will chose radius <6 and radius < 8 for idx2 and idx10 repectively.
manacher algorithm

2 Likes

link
second was exactly this question,you could search it online, you could also solve 4 th using same concept, i guess, so you make array of each 10 digit indexes, then you apply the given algorithm and pair you got,lets say p, then p.second-p.first is your required answer.apply only on odd idx.

for 3rd question i got partial, obviously i went wrong somewhere, but its basically max idx of {1,3,7,15…}denoting the height of one branch and other branch{2,6,14,30…} and sum of this two is ans.
note::its not correct, but it got me more than half test cases running.

it will not work on 3rd case.use another approach, you have to first calculate all states of all numbers, that total n*lgn , its graph question then.

For people who were stuck at the 3rd problem, the constraints mentioned 1<=N. Sadly N=0 was definitely an input in 9 of the testcases.

You missed N=0, not your mistake.

I was able to solve 5 Questions. Unable to solve 4th one.

123456
112233
These were the cases where you were supposed to print -1

can anyone share their code for the 2nd problem and the 4th problem ?

4th one is similar to the 2nd one…

where no char have odd frequency