id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

longestBalanced


Given a string of a's and b's "abbaabababaaaaaababababbba" return the length of the longest sequence of consecutive letters that has equal counts of a and b. This should be done in O(n) time, use a hashMap to help you keep track of things. The hint: treat a as -1 and b as +1, how do you know if a sequence has a balanced section?


longestBalanced("a") → 0
longestBalanced("") → 0
longestBalanced("abab") → 4

...Save, Compile, Run (ctrl-enter)

public int longestBalanced(String s) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Copyright Nick Parlante 2017 - privacy