Help me see the test cases of FIZZBUZZ2304 problem

My issue

I wish to know the test cases to check my solution

My code

 process.stdin.resume()
 process.stdin.setEncoding('utf-8')
 let inputStr = ''
 process.stdin.on('data',(input)=>{inputStr+=input})
 process.stdin.on('end',()=>{main()})
 
 function chunk (arr, nChunks){
     return arr.reduce((acum,_,index)=>{
         if(index%nChunks===0){
             acum.push(arr.slice(index, index + nChunks))
         }
         return acum
     },[])
 }
function main (){
    const arrayInput =  inputStr.split('\n')
    const nTest = arrayInput.shift()
    arrayInput.pop()
    let resp = ''
    const testCases = chunk(arrayInput, nTest)
          
    
    for(let i =0; i< nTest; i++){
    const k = testCases[i][0].split(' ')
    const arrNumbers = testCases[i][1].split(' ')  
      resp+=countOperation(k[1],arrNumbers)+'\n'
    }
    console.log(resp)
    
}
function isAnyOdd(nArr){
    return nArr.some((n)=>n%2===1)
}

function countOperation (K, array){
    let count = 0
    const KI = parseInt(K)
    for(let i = 0; i < array.length; i++){
        if(!!array[i+KI-1]){
            const tempArray = array.slice(i, i + KI)
            if(isAnyOdd(tempArray)){
                count++
            }
        }
    }    
    return count
}



Problem Link: FIZZBUZZ2304 Problem - CodeChef

Waiting :3

still waiting

@leonar6
Hi , I don’t have good hand of js , so unable to debug your code .
Plzz refer the following js solution for better understanding.

process.stdin.resume();
process.stdin.setEncoding("utf8");

let input_string = "";
let input_array = [];
let currentLine = 0;

process.stdin.on("data", (data) => {
   input_string = input_string + data;
});

process.stdin.on("end", () => {
   input_array = input_string.split("\n");
   main();
});

const readLine = () => {
   let res = input_array[currentLine];
   currentLine = currentLine + 1;
   return res;
};

const main = () => {
   let t = +readLine();
   while (t--) {
       let [n, k] = readLine()
           .split(" ")
           .map((n) => +n);
       let arr = readLine()
           .split(" ")
           .map((n) => +n);
       console.log(solution(n, k, arr));
   }
};
const solution = (n, k, arr) => {
   let odds = 0;
   let res = 0;
   for (let i = 0; i < k; i++) {
       if (arr[i] % 2 === 1) odds++;
   }
   if (odds > 0) res += 1;
   for (i = k; i < n; i++) {
       if (arr[i] % 2 === 1) {
           odds += 1;
       }
       if (arr[i - k] % 2 === 1) {
           odds -= 1;
       }
       if (odds > 0) res += 1;
   }
   return res;
};

Okay thank you, I will try to find the differences between my version

1 Like