feat: refactored docs structure

This commit is contained in:
Prad Nukala committed 2026-10-05 14:22:28 -04:00
1 parent 31a1fcfdbd
commit 6247915ae5
222 files changed
+6452 -729

No files matched your search

@@ -0,0 +1,75 @@
---
title: '150. Evaluate Reverse Polish Notation'
description: You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation
icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Math", slug: "math" }
- { name: "Stack", slug: "stack" }
video: "iu0082c4HDE"
issue: "https://github.com/prdlk/leetcode/issues/69"
sidebar:
label: 'Evaluate Reverse Polish Notation'
badge: 'Medium'
---
### Example 1:
- Input: `tokens = ["2","1","+","3","*"]`
- Output: `9`
- Explanation: `((2 + 1`) * `3`) = `9`
### Example 2:
- Input: `tokens = ["4","13","5","/","+"]`
- Output: `6`
- Explanation: `(4 + (13 / 5`)) = `6`
### Example 3:
- Input: `tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]`
- Output: `22`
- Explanation: `((10 * (6 / ((9 + 3`) * `-11`))) + `17`) + `5 = ((10 * (6 / (12 * -11`))) + `17`) + `5 = ((10 * (6 / -132`)) + `17`) + `5 = ((10 * 0`) + `17`) + `5 = (0 + 17`) + `5 = 17 + 5 = 22`
### Constraints:
- `1 <= tokens.length <= 10^4`
- `tokens[i]` is either an operator: "+", "-", "*", or "/", or an integer in the range [-200, 200].
## Approach
```mermaid
flowchart TD
S(["evalRPN(tokens)"]) --> I["stack = [], operations = + - * /"]
I --> L{"more token c?"}
L -- no --> E(["return stack[0]"])
L -- yes --> Q{"c is an operator?"}
Q -- no --> N["stack.append(int(c))"]
N --> L
Q -- yes --> P["y = stack.pop(), x = stack.pop() — order matters"]
P --> C["stack.append(operations[c](x, y))"]
C --> L
```
## Solution
```py
class Solution:
def evalRPN(self, tokens: List[str]) -> int:
stack = []
operations = {
"+": lambda x, y: int(x + y),
"-": lambda x, y: int(x - y),
"*": lambda x, y: int(x * y),
"/": lambda x, y: int(x / y),
}
for c in tokens:
if c in operations:
y = stack.pop()
x = stack.pop()
calc_func = operations[c]
result = calc_func(x, y)
stack.append(result)
else:
stack.append(int(c))
return stack[0]
```
@@ -0,0 +1,82 @@
---
title: '155. Min Stack'
description: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time
icon: dot
topics:
- { name: "Stack", slug: "stack" }
- { name: "Design", slug: "design" }
video: "qkLl7nAwDPo"
issue: "https://github.com/prdlk/leetcode/issues/68"
sidebar:
label: 'Min Stack'
badge: 'Medium'
---
::::warning
You must implement a solution with O(1) time complexity for each function.
::::
### Example 1:
- Input: ``
- Output: ``
- Explanation: Input `["MinStack","push","push","push","getMin","pop","top","getMin"]` [[],[-2],[0],[-3],[],[],[],[]] Output `[null,null,null,null,-3,null,0,-2]` Explanation MinStack minStack = new MinStack(); minStack.push(-2); minStack.push(0); minStack.push(-3); minStack.getMin(); // return `-3` minStack.pop(); minStack.top(); // return `0` minStack.getMin(); // return `-2`
### Constraints:
- `-2^31 <= val <= 2^31 - 1`
- Methods pop, top and getMin operations will always be called on non-empty stacks.
- At most 3 * 10^4 calls will be made to push, pop, top, and getMin.
## Approach
```mermaid
flowchart TD
subgraph state["two parallel stacks — same depth, always"]
A["stack — the values"]
B["minStack — the minimum as of that depth"]
end
state --> P
subgraph P["push(value)"]
P1["stack.append(value)"] --> P2["minStack.append(min(value, minStack[-1]))"]
end
state --> O
subgraph O["pop()"]
O1["pop both stacks together"]
end
state --> R
subgraph R["top() / getMin() — O(1)"]
R1(["stack[-1] / minStack[-1]"])
end
```
## Solution
```py
class MinStack:
def __init__(self):
self.stack = []
self.minStack = []
def push(self, value: int) -> None:
self.stack.append(value)
value = min(value, self.minStack[-1] if self.minStack else value)
self.minStack.append(value)
def pop(self) -> None:
self.stack.pop()
self.minStack.pop()
def top(self) -> int:
return self.stack[-1]
def getMin(self) -> int:
return self.minStack[-1]
# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(value)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()
```
@@ -0,0 +1,77 @@
---
title: '20. Valid Parentheses'
description: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid
icon: dot
topics:
- { name: "String", slug: "string" }
- { name: "Stack", slug: "stack" }
- { name: "Bracket Sequences", slug: "bracket-sequences" }
video: "WTzjTskDFMg"
issue: "https://github.com/prdlk/leetcode/issues/67"
sidebar:
label: 'Valid Parentheses'
badge: 'Easy'
---
### Example 1:
- Input: `s = "()"`
- Output: `true`
### Example 2:
- Input: `s = "()[]{}"`
- Output: `true`
### Example 3:
- Input: `s = "(]"`
- Output: `false`
### Example 4:
- Input: `s = "([])"`
- Output: `true`
### Example 5:
- Input: `s = "([)]"`
- Output: `false`
### Constraints:
- `1 <= s.length <= 10^4`
- `s` consists of parentheses only '()[]{}'.
## Approach
```mermaid
flowchart TD
S(["isValid(s)"]) --> I["stack = [], pairs = closer to opener"]
I --> L{"more char c?"}
L -- no --> Z{"stack empty?"}
Z -- yes --> T(["return True"])
Z -- no --> U(["return False — unclosed openers left"])
L -- yes --> Q{"c is a closer?"}
Q -- no --> A["stack.append(c) — it is an opener"]
A --> L
Q -- yes --> M{"stack non-empty and pairs[c] == stack[-1]?"}
M -- yes --> P["stack.pop() — matched"]
P --> L
M -- no --> F(["return False — mismatch"])
```
## Solution
```py
class Solution:
def isValid(self, s: str) -> bool:
stack = []
pairs = {")": "(", "]": "[", "}": "{"}
for c in s:
if c in pairs:
if stack and pairs[c] == stack[-1]:
stack.pop()
else:
return False
else:
stack.append(c)
return True if not stack else False
```
@@ -0,0 +1,62 @@
---
title: '71. Simplify Path'
description: You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this absolute path into its simplified canonical path
icon: dot
topics:
- { name: "String", slug: "string" }
- { name: "Stack", slug: "stack" }
issue: "https://github.com/prdlk/leetcode/issues/70"
sidebar:
label: 'Simplify Path'
badge: 'Medium'
---
### Example 1:
- Input: `path = "/home/"`
- Output: `"/home"`
- Explanation: The trailing slash should be removed.
### Example 2:
- Input: `path = "/home//foo/"`
- Output: `"/home/foo"`
- Explanation: Multiple consecutive slashes are replaced by a single one.
### Example 3:
- Input: `path = "/home/user/Documents/../Pictures"`
- Output: `"/home/user/Pictures"`
- Explanation: A double period ".." refers to the directory up a level (the parent directory).
### Example 4:
- Input: `path = "/../"`
- Output: `"/"`
- Explanation: Going one level up from the root directory is not possible.
### Example 5:
- Input: `path = "/.../a/../b/c/../d/./"`
- Output: `"/.../b/d"`
- Explanation: "..." is a valid name for a directory in this problem.
### Constraints:
- `1 <= path.length <= 3000`
- `path` consists of English letters, digits, period '.', slash '/' or '_'.
- `path` is a valid absolute Unix path.
## Solution
```py
class Solution:
def simplifyPath(self, path: str) -> str:
stack = []
segments = [item for item in path.split("/") if item]
for p in segments:
if stack and p == "..":
stack.pop()
elif not stack and p == ".." or p == ".":
continue
else:
stack.append(p)
return "/" + "/".join(stack)
```
@@ -0,0 +1,5 @@
---
title: Stack
description: 'Items are added and removed from one end, so the last item added is the first item removed.'
hidden: true
---
@@ -0,0 +1,3 @@
import { defineMeta } from "blume";
export default defineMeta({ title: "Stack", order: 6, icon: "layers", display: "page" });