Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1. Note that the returned integer should fit in 32-bit integer, if there is a valid answer but it does not fit in 32-bit integer, return -1.
CodingStaff+
Leetcode 2454. Next Greater Element IV
For each element in nums, find the first element to its right that is strictly greater and then the next strictly greater element after that (i.e., the "second greater" to the right), or return -1 if none exists. The challenge is to compute all answers efficiently for n up to 1e5, typically using monotonic-stack techniques to track candidate indices.
Contextos reais
Onde essa pergunta já apareceu
Use esses exemplos para entender em que contexto ela costuma cair e adaptar sua prática.
DoorDashstaff_plusjun. de 2025
Anexos públicos
Materiais associados
Nenhum anexo público associado a esta pergunta.
Sinais de resposta forte
Você deixa claro por que escolheu essa abordagem e o que descartou.
Seu código vem acompanhado de testes mentais e edge cases relevantes.
Sua explicação ajuda o entrevistador a acompanhar o raciocínio em tempo real.
O que costuma enfraquecer a resposta
Entrar direto no código sem alinhar interpretação do problema.
Passar tempo demais em silêncio e só explicar no fim.
Ignorar complexidade, invariantes e estratégia de teste.
Continue a preparação com o banco completo
No app você encontra perguntas parecidas, compara empresas e aprofunda essa busca com mais filtros.