Created
March 28, 2020 21:19
-
-
Save franzese/723c0498ff45872b2da579c3b9a655cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf-8'); | |
let inputString = ''; | |
let currentLine = 0; | |
process.stdin.on('data', function(inputStdin) { | |
inputString += inputStdin; | |
}); | |
process.stdin.on('end', function() { | |
inputString = inputString.split('\n'); | |
main(); | |
}); | |
function readLine() { | |
return inputString[currentLine++]; | |
} | |
/* | |
* Complete the 'fountainActivation' function below. | |
* | |
* The function is expected to return an INTEGER. | |
* The function accepts INTEGER_ARRAY locations as parameter. | |
*/ | |
function fountainActivation(locations) { | |
// Write your code here | |
let i = 0, fountainCount = 0; | |
while(i < locations.length) { | |
let fountainWidth = locations[i]; | |
console.log(fountainWidth); | |
i += fountainWidth; | |
fountainCount++; | |
} | |
return fountainCount; | |
} | |
function main() { | |
const ws = fs.createWriteStream(process.env.OUTPUT_PATH); | |
const locationsCount = parseInt(readLine().trim(), 10); | |
let locations = []; | |
for (let i = 0; i < locationsCount; i++) { | |
const locationsItem = parseInt(readLine().trim(), 10); | |
locations.push(locationsItem); | |
} | |
console.log(locations) | |
const result = fountainActivation(locations); | |
ws.write(result + '\n'); | |
ws.end(); | |
} | |
// [1,1,1] -> 1 | |
// [1,1,3,1,1] -> 1 | |
// [1,2,1,2,1] -> 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment