From d18066ccd17365894fd044a621d9328bd35a3980 Mon Sep 17 00:00:00 2001 From: Poornakumar Rasiraju Date: Tue, 22 Jul 2025 00:09:26 -0700 Subject: [PATCH] Replaced stack[stack.length - 1] with stack.at(-1) --- patterns/javascript/monotonicStack.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patterns/javascript/monotonicStack.js b/patterns/javascript/monotonicStack.js index 94918c4..5c17512 100644 --- a/patterns/javascript/monotonicStack.js +++ b/patterns/javascript/monotonicStack.js @@ -5,7 +5,7 @@ class MonotonicStack { let stack = []; // Stack stores indices for (let i = 0; i < n; i++) { - while (stack.length > 0 && nums[i] > nums[stack[stack.length - 1]]) { + while (stack.length > 0 && nums[i] > nums[stack.at(-1)]) { let index = stack.pop(); result[index] = nums[i]; } @@ -20,7 +20,7 @@ class MonotonicStack { let stack = []; // Monotonic decreasing stack for (let i = 0; i < n; i++) { - while (stack.length > 0 && temperatures[i] > temperatures[stack[stack.length - 1]]) { + while (stack.length > 0 && temperatures[i] > temperatures[stack.at(-1)]) { let prevIndex = stack.pop(); result[prevIndex] = i - prevIndex; }