Enormous input test problem

Thanks in advance…
I am little confused in the problem.
link to the question statement : INTEST Problem - CodeChef
I have made out two solutions which are correct and have very slight difference in them. The problem is on solution is always exceeding time limit while other is accepted. I wanted to ask why is that happening. And why is that slight change inpacting the time of solving the problem.
ONE SOLUTION: process.stdin.resume();
process.stdin.setEncoding(‘utf8’);

let input = ‘’;
process.stdin.on(‘data’, function(chunk) {
input += chunk
})

process.stdin.on(‘end’, function(){
input = input.split(‘\n’)
func()
})

function func(){
let [n,k] = input[0].split(’ ')
n = parseInt(n)
k = parseInt(k)
let ans = 0;
for(let i = 1; i<= n;i++){
let sample = parseInt(input[i])
if(sample % k === 0){
ans++
}
}
console.log(ans)
}
SECOND SOLUTION:
process.stdin.resume();
process.stdin.setEncoding(‘utf8’);

let input = ‘’;
process.stdin.on(‘data’, function(chunk) {
input += chunk
input = input.split(‘\n’)
let [n,k] = input[0].split(’ ')
n = parseInt(n)
k = parseInt(k)
let ans = 0;
for(let i = 1; i<= n;i++){
let sample = parseInt(input[i])
if(sample % k === 0){
ans++
}
}
console.log(ans)
})

Thanks for reading, Please reply.:blush: