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

SOLID & Ruby in 5 short examples

Is GraphQL is better than REST?

Autoscaling in AWS Part 1: Autoscale ECS Services

Plug Talk — 8/12

Exploiting XXE via File Upload

CI/CD for Cloud-Native Applications

Java9 : Process API Updates #1

Protecting PostgreSQL using pg_basebackup with IBM Spectrum Protect

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

DATA STRUCTURES.

Understanding Data Structures: Linked Lists

Data Structures: Queue

Interview questions 2022 basic javascript