Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Nghĩa Huỳnh Trung
Another Implement Using GO + Array

Nghĩa Huỳnh Trung

Jun 24, 2025

func (this *Solution) nextLargerElement(arr []int) []int { res := make([]int, len(arr)) stack := make([]int, 0) for i := len(arr) - 1; i >= 0; i-- { length := len(stack) for length > 0 { if arr[i] < stack[length-1] { res[i] = stack[length-1] stack = append(stack, arr[i]) break } length-- } if length == 0 { res[i] = -1 stack = append(stack, arr[i]) continue } } return res }

0

0

Comments
Comments

On this page

Problem Statement

Examples

Solution:

Algorithm Walkthrough

Code

Complexity Analysis

Time Complexity

Space Complexity