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.
Every time you delete a pair of letters, you create a new String. So you have to restart at the beginning of the new string to find potential new pairs.
Example:
baab
Without the i = 0, you will delete the letters "aa". The new string is "bb", but you won't delete those two letters cause your loop is already done.
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 →
It's not working without i = 0 for me.
Every time you delete a pair of letters, you create a new String. So you have to restart at the beginning of the new string to find potential new pairs.
Example: baab
Without the i = 0, you will delete the letters "aa". The new string is "bb", but you won't delete those two letters cause your loop is already done.