HackerRank (Stacks) - Maximum element solution gets a timeout Apparently my solution is really slow. Can someone help me with why my solution passes a little over half the test cases for this question?

Here is my solution:

function processData(input) {
    //Enter your code here

    let inputArr = input.split("\n");
    let newArr = inputArr.map(x =&gt; x.split(" ").map(p =&gt; parseInt(p, 10)));
    let stack = [];
    let len = newArr.length;
    for (let i = 0; i &lt; len; i++){
        if (newArr[i][0] === 1){
            stack.push(newArr[i][1]);
        } else if (newArr[i][0] === 2){

            stack.pop();

        } else if (newArr[i][0] === 3){
            console.log(stack.reduce(maxNum));
        }
    }

}

let maxNum = (acc, curr) =&gt; Math.max(acc, curr);
Performance review
These code challenges have tight constraints (a very good thing in my view) so you you must be aware of the actual load on the CPU for every line you write.
Also these code challenges run on V8, and sometimes that version is not up to date. It helps to have some knowledge of some of V8's oddities, past and present.
Looking at your code.
The first problem is the parsing of the input. Using Array.map is convenient but slow.
Rather than parse the input before you process it, combine the processing with the parsing. This will save a significant amount of time.
Don't slice arrays if you don't need to, there are better ways to access data in arrays if speed is important.
Same with Array.reduced, there is no need for it in this example.
Use Number(&quot;42&quot;) to convert to number rather than parseInt as it is quicker. There really is only one use for parseInt and that is to convert numbers from bases other than 10.
The commands (first value per line after first line) are not used as numbers, you don't need to convert them.
RegExps are very quick compared to loops, iterators, and many of the array functions. Its well worth learning RegExps to get the most out of your code.
You can use a RegExp to split the input. input.split(/[^0-9]/g); will split on each non digit and a zillion times faster than using String.split and array.map
Function calls add overhead that is not related to the algorithm. Avoid needless function calls if you can. That does not mean flatten out your code that means dont create indirect function calls if there is no need.
// completely redundant and only adds overhead.
let maxNum = (acc, curr) =&gt; Math.max(acc, curr);

V8 specific
Watch out when using let. Some of these code challenge sites are still running on older versions of V8 and let used to add a big overhead especially inside loops.
Careful with indexing indexing. Some JS engines are not as efficient as others when it comes to array indexing and property referencing.
For example V8 will be slower when you reference an array elements using multiple indexes
var c = 0;
for(var i = 0; i &lt; 10; i ++){
   for(var j = 0; j &lt; 100; j ++){
      c += myArray[i][j];
   }
}

You can improve the performance by staying as close to the required index as possible.
var c = 0;
for(var i = 0; i &lt; 10; i ++){
   const innerArray = myArray[i]; // only need to calculate i index 10 times
                                  // rather than 1000 times.
                                    
   for(var j = 0; j &lt; 100; j ++){
      c += innerArray[j];
   }
}

Note V8 has made some amazing improvements over the past months. It always pays to test performance when in doubt.
Rewrite
The following will be about the fastest possible. the only performance increase you could get is using a typed array and implementing your own stack (which is worth the effort for larger array sizes)
/* Commands first item is command count
1 x  -Push the element x into the stack.
2    -Delete the element present at the top of the stack.
3    -Print the maximum element in the stack. */
function processData(data) {
    const stack = [];
    const input = data.split(/[^0-9]/g); // RegExp to split the data
    var max, i, inPos = 0; // inPos is data read pos
    var count = Number(input[inPos++]); // You could get away without Number 
                                        // but using a number type is faster 
    while (count--) { //simplify the loop
       const command = input[inPos++];  // The command is not used as number
       if (command === &quot;1&quot;) { // compare to the string not number as its quicker
                            // in this situation
            // Older V8 the following is the fastest way to push to an array 
            stack[stack.length] = Number(input[inPos++]);
       } else if(command === &quot;2&quot;) {
            stack.pop();
       } else {
            // for and while loops are faster than array methods.
            i = stack.length;            
            // you dont know if length could be zero
            // but it says nothing about what to do for no value so I am
            // assuming it safe to get max from the top.
            max = stack[--i];
            while (i--) {
                // there may be a slight advantage to using the next line
                // but cant remember how much to, indexing stack twice may 
                // swing the balance
                // max = max &lt; stack[i] ? stack[i] : max;
                // over calling Math.max  
                max = Math.max(max, stack[i]);
            }
            console.log(max);
       }
    }
}

I find expanded and commented code hard to read so below is a neater version in my prefered style.
function processData(data) {
    const stack = [];
    const input = data.split(/[^0-9]/g);
    var count, max, i, inPos = 0;
    count = Number(input[inPos++]); 
    while (count--) { 
       const command = input[inPos++];
       if (command === &quot;1&quot;) { stack[stack.length] = Number(input[inPos++]) }
       else if (command === &quot;2&quot;) { stack.pop() }
       else {
            i = stack.length;            
            max = stack[--i];
            while (i--) { max = Math.max(max, stack[i]) }
            console.log(max);
       }
    }
}