Commented codes are always appreciated. . Upvote gives 10 karma. Will give 15 more if you properly document it
Ask yourself 3 questions.
- If freq(‘a’)\neq freq(‘b’) , what is the minimum change in contribution of next appendation w.r.t. first one?
- What is the largest possible length of original string S?
- How many appendations will it take for all future appendations to reach |S| or 0, provided that the contribution behaves monotonically (eg if increasing, always increase and vice cersa).
1 Like
Good job
Refer to O(|S|) solution for now. While trying to explain, I noticed @admin linked the wrong solution there. She linked the O({S}^{2}) solution there, I will get that fixed. Sorry for the inconvenience
Really interesting question and a really interesting and thought provoking approach.