A live stream logs viewer reactions in order as "up" or "down" in reactions.
Write longestBalancedRun(reactions) that returns the length of the longest run of back-to-back reactions with exactly as many "up" as "down". Return 0 if there is none.
Input: reactions = ["up","down","down","up","up","up","down"] Output: 6
Indexes 1 to 6 hold 3 ups and 3 downs.
Input: reactions = ["up","up"] Output: 0
There are no downs, so no run balances.
0 <= reactions.length <= 10^5"up" or "down".Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #46 Longest Balanced Reaction Run. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.