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.
Because while removing pairs, you might get some element from the beginning matching one at the end ending up as another pair. So he starts from the beginning to be safe and correct to eliminate all possible occurrences of pairs without having to resort to multiple loops.
Also he's regularly updating the same string used for comparison. So he starts from the beginning to its length always to check if any pairs occur. When a string occurs such that from i = 0 to s.length() no pairs occur that string is finally the required string. The loop terminates and the string is returned (or "Empty String" if the resultant s.length() == 0)
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 →
Because while removing pairs, you might get some element from the beginning matching one at the end ending up as another pair. So he starts from the beginning to be safe and correct to eliminate all possible occurrences of pairs without having to resort to multiple loops. Also he's regularly updating the same string used for comparison. So he starts from the beginning to its length always to check if any pairs occur. When a string occurs such that from i = 0 to s.length() no pairs occur that string is finally the required string. The loop terminates and the string is returned (or "Empty String" if the resultant s.length() == 0)