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.
Actually you don't need to make i=0 for each pair you find. In the worst case this will make the programme traverse the string again. Instead a better assignment would be i=i-1.
this is the most optimized assignment because if any new pairs are formed due to removal of the current detected pair it will be at position i-1 and i-2. Example:
....i-2 i-1 i i+1....
....b a a b......
after removing
....i-2 i-1....
....b b.....
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Super Reduced String
You are viewing a single comment's thread. Return to all comments →
Actually you don't need to make i=0 for each pair you find. In the worst case this will make the programme traverse the string again. Instead a better assignment would be i=i-1. this is the most optimized assignment because if any new pairs are formed due to removal of the current detected pair it will be at position i-1 and i-2. Example:
....i-2 i-1 i i+1.... ....b a a b......
after removing
....i-2 i-1.... ....b b.....