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.
- Prepare
- Algorithms
- Strings
- Bear and Steady Gene
- Discussions
Bear and Steady Gene
Bear and Steady Gene
Sort by
recency
|
177 Discussions
|
Please Login in order to post a comment
O(n) cpp solution, using two indices to keep track of min substrings, and pushing both indices until we find a new valid substring.
I find the optimal length of the substring to be replaced using binary search and for a given substring length I swipe through all possible substrings. The length of the substring to be replaced must be larger than the number of letters which I need to add to the rest of the string to compensate for the unequal number of letters in the latter. The solution scales as N*log(N)
thought this was a dynamic programming question, but turns out its just a simple log time search at each iteration algo.
O(n*log(n)) using lower bound
Haskell:
Haskell: