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.
On average input, the regex version was always within a factor of 2 of the stack version and appeared to be O(n). However, for large, unideal input (i.e. "(((((( ...") the regex solution is clearly O(n^2). Which makes sense of course. Both the while loop and replace regex are O(n)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Stacks: Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
I benchmarked the following against the stack version:
On average input, the regex version was always within a factor of 2 of the stack version and appeared to be O(n). However, for large, unideal input (i.e. "(((((( ...") the regex solution is clearly O(n^2). Which makes sense of course. Both the while loop and replace regex are O(n)