Min Num of Reversals to Make Sequence

Problem:

Example:

Solution:

const head = 1
const tails = 0
let start = 0
let next = 1
let counter = 0
makePattern = (input) => {

while (next < input.length) {
if(input[start] === head && input[next] === tails){ start ++ next ++ } else if(input[start] === head && input[next] === head) { input[next] = tails counter += 1 start ++ next ++ } else if(input[start] === tails && input[next] === head) { start ++ next ++ } else { input[next] = head counter += 1 start ++ next ++ } } return counter}

--

--

--

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

Recommended from Medium

Impress Your Friends With Code Splitting in React

Debugging Android wirelessly for React Native (made easy)

Creating Japanese Resources Social Network

Pass by value in Javascript

Setting up bloomberg radio stream in React

Setup Bootstrap for React

Setting up React Js for dummies (part 1)

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
Nerly Ton

Nerly Ton

More from Medium

What will it Cost to Build a Taxi-Booking App?

What will it cost to build a taxi-booking app?

MODULE PACK FOR STUDENT

Beauty Tech Fireside Chat: Post-Event Recap

FIRST PRE-SALE OF META FASTEST — RACE HORSES AND META BOX IS 10% OFF💥