Todos Novo

user:thomas gists created by user

title:mygist gists with given title

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

Registrar-se

Entrar


Todos Novo Registrar-se Entrar

All gists matching topic interview

Mais recente criado
Menos recente criado
Mais recente atualizado
Menos recente atualizado

linkjobai / Monotonic Stack: The Pattern Behind "Next Greater Element" Questions

0 curtidas
0 bifurcações
1 arquivos
Última atividade 1794541558
Interview prep notes
interview

Monotonic Stack: The Pattern Behind "Next Greater Element" Questions

If a question asks for the next greater, previous smaller, or "how many days until a warmer temperature", a monotonic stack usually turns an O(n²) scan into O(n).

Core idea

Keep a stack of indices whose values are in sorted order (decreasing for "next greater"). When a new value breaks the order, it is the answer for every index you pop.

def daily_temperatures(temps):          # LeetCode 739
Próximo Anterior

Desenvolvido por Opengist ⋅ Load: 50ms⋅

Português
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文