We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Stacks
- Maximum Element
- Discussions
Maximum Element
Maximum Element
Sort by
recency
|
1457 Discussions
|
Please Login in order to post a comment
function getMax(operations) { let arr = [], results = []; operations.forEach(element => { if (element.startsWith("1")) { arr.push(element.split(" ")[1]) } else if (element.startsWith("2") && arr.length !== 0) { arr.pop() } else if (element.startsWith("3")) { let max = Math.max(...arr); results.push(max); } }); return results; }
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )
c# solution :
C++ O(1)