Skip to content

Instantly share code, notes, and snippets.

@tonythomas01
Last active May 25, 2020 09:46
Show Gist options
  • Select an option

  • Save tonythomas01/9aa6bf46fe0eaaef1d7fb846f8b73ec2 to your computer and use it in GitHub Desktop.

Select an option

Save tonythomas01/9aa6bf46fe0eaaef1d7fb846f8b73ec2 to your computer and use it in GitHub Desktop.

Revisions

  1. tonythomas01 revised this gist May 25, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion testCasesWithLimits.js
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,6 @@ rl.on('line', (line) => {
    }

    // Ignore this first line now ?

    if (shouldProcessTestCaseLimit) {
    shouldProcessTestCaseLimit = false;
    testCaseLimit = +line;
  2. tonythomas01 created this gist May 25, 2020.
    47 changes: 47 additions & 0 deletions testCasesWithLimits.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    // Assume you have to read something like:
    // 3 - number of test cases that follow
    // 3 - limit in this test case.
    // 1 2 3 - test case data
    // 4
    // 1 2 3 4

    const readline = require('readline')
    const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
    });

    let firstLine = true;
    let numberOfTestCasesLine = true;

    let totalTestCasesCount = undefined;
    let testCasesProcessedCount = 0;

    let shouldProcessTestCaseLimit = true;
    let testCaseLimit;
    rl.on('line', (line) => {
    if (firstLine) {
    totalTestCasesCount = +line;
    firstLine = false;
    return;
    }

    // Ignore this first line now ?

    if (shouldProcessTestCaseLimit) {
    shouldProcessTestCaseLimit = false;
    testCaseLimit = +line;
    return;
    }

    console.log(`Processing test case line ${line}, with testCaseLimit: ${testCaseLimit}`);
    const numberArray = line.split(' ').map(Number);
    console.log("numberArray", numberArray);
    // Do your magic here.

    shouldProcessTestCaseLimit = true;
    testCasesProcessedCount++;
    if (totalTestCasesCount <= testCasesProcessedCount) {
    rl.close();
    }
    });