What am I doing Wrong here ? Help Please..

//https://www.codechef.com/submit/TABLET

“use strict”;

var input = ‘’;

function setinput(data) {
input += data;
}

function formatinput() {
input = input.split(/\s+/).map(Number);
}

function main() {
formatinput();
let cases = parseInt(input.splice(0, 1)[0]);;

for (let i = 0; i < cases; i++) {
let tabletsNum = parseInt(input.splice(0, 1)[0]);
let budget = parseInt(input.splice(0, 1)[0]);
let tabletArr = [];
let areaAndPriceArr = [];

for (let j = 0; j < tabletsNum; j++) {
  tabletArr[j] = input.splice(0, 3);
}

for (let item of tabletArr) {
  if (item[2] <= budget) {
    areaAndPriceArr.push([item[0] * item[1], item[2]]);
  }
}

if (areaAndPriceArr.length === 0) {

  console.log('no tablet')
  continue;
}

let max = 0;
let ans = 0;

for (let k = 0; k < areaAndPriceArr.length; k++) {
  if (areaAndPriceArr[1] > max) {
    ans = k;
  }
}

max = parseInt(areaAndPriceArr[ans][0]);

console.log(max);

}
process.exit();

}
process.stdin.resume();
process.stdin.setEncoding(‘utf8’);
process.stdin.on(‘data’, setinput).on(‘end’, main);

hey @adityalekhi
Thanks for asking your doubt

You just forget to update the “max” variable :point_down:

Correct code will be

if (areaAndPriceArr[k][0] > max) {  
    max=areaAndPriceArr[k][0];
    ans = k;
  }

Rest is fine in your code.