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.
String Reduction
String Reduction
Sort by
recency
|
67 Discussions
|
Please Login in order to post a comment
wow very misleading question.
spent alot of time, in vain, using the standard dynamic programming analysis, got no where because the choices of reduction for a string cant seem to be reduced to choices of reduction for its substrings, so the problem cant seem to be analyzed in terms of its subproblems - irreducible problem.
turns out the problem just requires finding the parity invariant under reductions, since any non constant string can be reduced to length 1 or 2 which have different parity composition.
O(n) no dynamic programming. very stupid question, why is it in dynamic programming when its just a trick question?
Python:
Here is my solution in java, javascript, python, C, C++, Csharp HackerRank String Reduction Problem Solution
Here is String Reduction problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-string-reduction-problem-solution.html
l = [s.count('a'),s.count('b'),s.count('c')) while(l.count(0)<2): l.sort(reverse=True) l[0]-=1 l[1] -= 1 l[2] += 1 return max(l)