Created
April 17, 2022 06:16
-
-
Save MohamedGamil/007c5afc0088638b341235b384fd3fca to your computer and use it in GitHub Desktop.
HackerRank / A Very Big Sum
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 'aVeryBigSum' function below. | |
* | |
* The function is expected to return a LONG_INTEGER. | |
* The function accepts LONG_INTEGER_ARRAY ar as parameter. | |
*/ | |
function aVeryBigSum(ar) { | |
let bigSum = BigInt('0'); | |
for(let bigInt of ar) { | |
bigSum += BigInt(bigInt); | |
} | |
return bigSum.toString(); | |
} | |
function main() { | |
const ws = fs.createWriteStream(process.env.OUTPUT_PATH); | |
const arCount = parseInt(readLine().trim(), 10); | |
const ar = readLine().replace(/\s+$/g, '').split(' ').map(arTemp => parseInt(arTemp, 10)); | |
const result = aVeryBigSum(ar); | |
ws.write(result + '\n'); | |
ws.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment