Solving Popular Algorithms: Balancing Strings

A kitty trying to find balance
s = "RLRRLLRLRL"
balancedStringSplit = (s) => {
let balance = 0
let answer = 0
for (let char of s) {

if (char === "R") {
balance++
} else {
balance--
}
if (balance === 0) {
answer++
}
}
return answer
};
A monkey with perfect balance

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Cool trick: open any Github repo in vscode online!

Configuring CI/CD on Kubernetes with Jenkins

Beginners guide to CSS Fonts

Dissecting C++ Part 3: Linker

DOCKER (What is Docker?)

Building infrastructure products: talk to your users

Using Git in Data Science: the Solo Master

Computer Science: Linked Lists

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
HopeGiometti

HopeGiometti

More from Medium

Arrays Data Structures Explained

Where Visuals And Algorithms Collide

Sliding Window Algorithm

Data Structure — Linked List