CP in nodejs

Can you provide article to get started competitive programming in javascript with node.
I am currently using java, but sometimes in OA requires JS also for solving questions. Can you provide a bit detail about npm packages that will be helpful for stuff like sorting, comparator, priorityqueue , arraylist etc

I have submitted a few codes in nodeJs. Here is the starter template

'use strict';


let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n');    

function readLine(){
    return inputString[currentLine++];

function main(){
    // input in nodeJs
	let test = parseInt(readLine(),10);
		let n = parseInt(readLine(),10);
        // output in nodeJs
		if(n%2 == 0)
  1. I ain’t sure how to solve interactive problems using node as it seems it reads all input at once and the parses them as asked.
  2. I won’t recommend using nodeJs (at least on codechef) as I have witnessed situations where solution with same complexity, passes in c++/ python but gets TLE in node (maybe because problem settlers don’t check the solution in this language or maybe the time multiplier is low for it or maybe fast i/o tricks > good algo).

Here are some of my other solutions using nodeJs:
1   2   3   4   5   6   7   8   9
Though these are very basic, going through them will give you a basic overview of common syntax/ ds. If you have more time, you can scroll back to my submission history to find more (if any).

1 Like

Thanks, What about heap, which is prioirtyqueue in java.

Thanks, What about heap, which is prioirtyqueue in java.

Assuming you meant javascript, honestly I didn’t continue with nodeJs due to above mentioned reasons. You may wait and expect any nodeJs experienced programmer to answer this question or go to google/ submission list of some problem that requires those data-structures and learn how to use them in Js.

1 Like