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.
Assuming you understood everything above that part, u must have realised that if the difference p is odd, two cases arise...and in that non-trivial case when the string becomes empty(like in the example "aba")during the process when u delete extra elements so that the no. of operations reaches k,realise that the string should become empty in less than or equal to p/2 operations(the other delete operations will be "just like that")(i at this point of time is denoting the no. of characters left in the string is).so u can also write --- if(p/2>=i)....
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Append and Delete
You are viewing a single comment's thread. Return to all comments →
Assuming you understood everything above that part, u must have realised that if the difference p is odd, two cases arise...and in that non-trivial case when the string becomes empty(like in the example "aba")during the process when u delete extra elements so that the no. of operations reaches k,realise that the string should become empty in less than or equal to p/2 operations(the other delete operations will be "just like that")(i at this point of time is denoting the no. of characters left in the string is).so u can also write --- if(p/2>=i)....