识别信号
- Look for the candidate's ability to apply stack-based state management to a real-world path traversal problem.
- Assess how well the candidate handles edge cases like empty or root paths and redundant slashes.
- You might be prompted to explain why a naive O(n^2) approach fails for large histograms.
解题流程
- 1. 明确窗口/状态定义
- 2. 更新状态并维护约束
- 3. 用边界样例验证
常见失分点
- Forgetting to handle consecutive slashes as a single slash, which can lead to incorrect paths.
- Forgetting to add a sentinel zero-height bar to process remaining stack elements.
- Using float division instead of truncating toward zero, causing wrong integer results.
推荐题单梯度
简化路径
Simplify a Unix-style path by transforming it into its canonical form using stack-based state management.
柱状图中最大的矩形
Find the maximal rectangular area in a histogram using stack-based state management for precise bar tracking and width c…
逆波兰表达式求值
Compute the result of an arithmetic expression in Reverse Polish Notation using a stack to manage operands efficiently.
最小栈
Design a stack with O(1) operations to push, pop, retrieve the top element, and get the minimum element in constant time…
基本计算器
Implement a basic calculator to evaluate mathematical expressions, ensuring correct evaluation with stack-based manageme…
用队列实现栈
This problem tests your ability to simulate a LIFO stack using two queues while preserving all standard stack operations…
基本计算器 II
Basic Calculator II evaluates a mathematical expression with operators and integers, handling basic arithmetic with prec…
用栈实现队列
Implement a queue using two stacks, focusing on stack-based state management to achieve FIFO behavior in a queue.
去除重复字母
Remove duplicate letters from a string to produce the lexicographically smallest result using stack-based state manageme…
迷你语法分析器
Deserialize a nested list string using stack-based state management, handling integers and nested lists with depth-first…
文件的最长绝对路径
Find the length of the longest absolute file path in a filesystem string using stack-based depth tracking efficiently.
字符串解码
Decode a nested encoded string using stack-based state management, handling repeated patterns efficiently with recursion…
移掉 K 位数字
Remove K Digits requires selecting which digits to drop using a monotonic stack for the smallest possible integer result…
下一个更大元素 II
Solve the Next Greater Element II problem by using a stack-based state management approach for circular arrays.
标签验证器
The Tag Validator problem involves validating a code snippet by parsing through tags using a stack-based state managemen…
函数的独占时间
Solve the 'Exclusive Time of Functions' problem using stack-based state management for accurate function execution time …
棒球比赛
Simulate baseball score operations using a stack-based approach to compute the final score after all operations.
原子的数量
Compute the exact count of each atom in a chemical formula using stack-based state management and hashing techniques eff…
小行星碰撞
Determine the final positions of moving asteroids using a stack-based simulation for efficient collision resolution in l…
Lisp 语法解析
Parse Lisp expressions using stack-based state management to evaluate variables and operations.
每日温度
In the Daily Temperatures problem, you need to find out how many days to wait for a warmer temperature based on given da…
最多能完成排序的块 II
Determine the maximum number of chunks you can split an array into so that sorting each chunk results in a fully sorted …
最多能完成排序的块
The Max Chunks To Make Sorted problem requires you to split an array into the maximum number of chunks that can be sorte…
基本计算器 IV
Simplify mathematical expressions using stack-based state management, handling variables, operators, and polynomial term…
车队
The Car Fleet problem asks how many car fleets will reach a target given their starting positions and speeds, considerin…
括号的分数
Calculate the score of a balanced parentheses string using stack-based state management for an optimal solution.
索引处的解码字符串
Decode the string and find the k-th letter efficiently using stack-based state management in this problem.
最大频率栈
Design a stack-like data structure to manage elements and handle frequent stack operations, including popping the most f…
股票价格跨度
Design an efficient algorithm using stacks to calculate the stock span for daily price quotes.
使括号有效的最少添加
Compute the minimum insertions needed to make a parentheses string valid using efficient stack-based state tracking tech…
戳印序列
Solve Stamping The Sequence with stack-based state management to convert string s to target using stamp efficiently.
验证栈序列
Determine if a sequence of push and pop operations can produce the given popped array using a stack-based state approach…
检查替换后的词是否有效
Determine if a string can be built from repeated 'abc' insertions using stack-based state management, verifying sequence…
笨阶乘
Compute the clumsy factorial of a number using a fixed rotation of multiply, divide, add, and subtract operations effici…
删除最外层的括号
Remove Outermost Parentheses simplifies a valid parentheses string by removing the outermost layers of parentheses in ea…
删除字符串中的所有相邻重复项
Solve Remove All Adjacent Duplicates In String by simulating deletions with a stack that collapses matching neighbors im…
不同字符的最小子序列
The Smallest Subsequence of Distinct Characters problem asks you to find the lexicographically smallest subsequence of a…
花括号展开 II
Solve Brace Expansion II efficiently by using stack-based state management to generate all unique combinations of nested…
解析布尔表达式
Solve the "Parsing A Boolean Expression" problem by evaluating boolean expressions using stack-based state management, r…
有效括号的嵌套深度
This problem challenges you to compute the maximum nesting depth of two valid parentheses strings using stack-based stat…
餐盘栈
Design a system that manages dinner plate stacks using stack-based state management, handling dynamic plate placement an…
反转每对括号间的子串
Reverse all substrings within matched parentheses using a stack-based approach for efficient state tracking and reversal…
删除字符串中的所有相邻重复项 II
Remove all adjacent duplicates in the string using stack-based state management with a given threshold k.
移除无效的括号
Given a string with parentheses and letters, remove the fewest parentheses to produce any valid balanced string efficien…
设计一个支持增量操作的栈
Implement a stack that supports push, pop, and targeted increment operations efficiently using array-based state managem…
用栈操作构建数组
Simulate stack operations to match a target array while processing numbers from 1 to n.
商品折扣后的最终价格
Calculate final prices with discounts applied in a shop using a stack-based state management approach to find the correc…
平衡括号字符串的最少插入次数
Compute the minimum insertions to transform a parentheses string into a balanced string using efficient stack tracking.
整理字符串
This problem requires removing adjacent characters that cancel each other out, leveraging stack-based state management.
文件夹操作日志搜集器
Simulate folder navigation based on a list of operations to determine the current folder depth.
括号的最大嵌套深度
Find the maximum nesting depth of parentheses in a valid string using stack-based state management.
找出最具竞争力的子序列
Identify the lexicographically smallest subsequence of size k using stack-based greedy selection in array traversal.
无法吃午餐的学生数量
Simulate a queue of students with sandwich preferences and determine how many can't eat based on available sandwiches.
删除子字符串的最大得分
Compute the highest score by greedily removing specific substrings using a stack to track state transitions efficiently.
车队 II
Car Fleet II involves calculating collision times between cars traveling at different speeds along a one-lane road using…
子数组最小乘积的最大值
The problem asks to find the maximum min-product of any non-empty subarray of nums.
删除一个字符串中所有出现的给定子字符串
Remove all occurrences of a specified substring from a string using efficient stack-based state management.
队列中可以看到的人数
Compute how many people each person in a queue can see to their right using efficient stack-based state management.
游戏中弱角色的数量
Identify all weak characters in a game by analyzing attack and defense values using a stack-based greedy sorting approac…
含特定字母的最小子序列
Find the lexicographically smallest subsequence of length k with at least repetition occurrences of a given letter using…
子数组范围和
Compute the total sum of ranges for all contiguous subarrays efficiently using stack-based state management techniques.
判断一个括号字符串是否有效
Determine if a parentheses string can be transformed into a valid sequence considering locked positions using stack logi…
替换数组中的非互质数
Replace Non-Coprime Numbers in Array uses stack-based state management to iteratively merge adjacent non-coprime integer…
统计道路上的碰撞次数
Count Collisions on a Road is a problem where you calculate the number of car collisions based on their movements in a s…
美化数组的最少删除数
Determine the minimum deletions required to transform an array into a beautiful sequence using stack-based state managem…
巫师的总力量和
The Sum of Total Strength of Wizards problem asks for the sum of the total strengths of all contiguous subarrays of wiza…
元素值大于变化阈值的子数组
Find the size of a subarray with all elements greater than threshold divided by length using stack-based state managemen…
根据模式串构造最小数字
Construct the lexicographically smallest string that fits the increasing and decreasing conditions of a given pattern.
从字符串中移除星号
Remove all stars from a string by simulating the removal process using a stack to manage characters and stars efficientl…
使用机器人打印字典序最小的字符串
Solve the problem of using a robot to print the lexicographically smallest string with stack-based state management.
删除子串后的字符串最小长度
Determine the smallest string length after repeatedly removing AB or CD substrings using stack-based simulation techniqu…
机器人碰撞
Robot Collisions involves simulating robot movements and handling collisions with stack-based state management.
操作使得分最大
Maximize the score by applying operations on a subarray at most k times, utilizing stack-based state management.
美丽塔 I
Solve Beautiful Towers I by testing each peak and enforcing mountain limits with monotonic stack style height propagatio…
美丽塔 II
Maximize tower configurations with the stack-based approach while ensuring mountain-like patterns in this medium difficu…
删除星号以后字典序最小的字符串
Find the lexicographically smallest string by removing stars using stack-based state management and careful character se…
清除数字
Remove all digits from a given string by applying a repeated operation to form the final string without digits.
计算字符串的镜像分数
Calculate the mirror score of a string using stack-based state management for matching letters efficiently and accuratel…
最多 K 个元素的子数组的最值之和
Compute the sum of maximum and minimum values in all subarrays up to size k using efficient stack-based state management…
非递减数组的最大长度
Determine the maximum size of a non-decreasing array by replacing subarrays with their maximum values efficiently.
移除相邻字符
This problem focuses on removing adjacent characters in a string using a stack-based approach until no more operations a…