-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblems_data-structures.json
More file actions
242 lines (242 loc) · 44.3 KB
/
Copy pathproblems_data-structures.json
File metadata and controls
242 lines (242 loc) · 44.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
[
{
"slug": "min-in-stack",
"title": "Stack Top After Pushes",
"module": "data-structures",
"statement": "A **stack** is a linear data structure that follows the **Last-In, First-Out (LIFO)** principle. The most recently added element is always the first one available for removal, making the top of the stack the most recently pushed value.\n\nIn this challenge, your task is to determine the value currently at the **top of the stack** after a sequence of push operations.\n\nThe input is a list representing values pushed onto an initially empty stack in the order they were received.\n\nYour function should return the value at the top of the stack after all pushes have been completed.\n\nIf no values were pushed, return **`-1`**.\n\nThis exercise reinforces several important programming concepts:\n\n* Understanding the **Last-In, First-Out (LIFO)** behavior of stacks.\n* Working with ordered collections.\n* Identifying the most recently inserted element.\n* Handling edge cases involving **empty data structures**.\n\nStacks are fundamental data structures used in function calls, expression evaluation, undo systems, browser navigation, compiler design, and many other software applications.",
"original_statement": "A **stack** is a linear data structure that follows the **Last-In, First-Out (LIFO)** principle. The most recently added element is always the first one available for removal, making the **top** of the stack the most recently pushed value.\n\nIn this challenge, your task is to determine the value currently at the **top of the stack** after a sequence of push operations.\n\nThe input is a list representing values pushed onto an initially empty stack in the order they were received.\n\nYour function should return the value at the top of the stack after all pushes have been completed. If no values were pushed, return **`-1`**.\n\nThis exercise reinforces several important programming concepts:\n\n- Understanding the **Last-In, First-Out (LIFO)** behavior of stacks.\n- Working with ordered collections.\n- Identifying the most recently inserted element.\n- Handling edge cases involving **empty data structures**.\n\nStacks are fundamental data structures used in function calls, expression evaluation, undo systems, browser navigation, compiler design, and many other software applications.",
"func_name": "StackTop",
"return_type": "int",
"param_types": ["[]int"],
"param_names": [],
"hints": ["In a **stack**, the **last value pushed** is always at the top.", "If the list contains values, the answer is simply the **last element**.", "If the list is **empty**, return **`-1**."],
"difficulty": 1,
"xp_reward": 70,
"constraints": "- `0 <= len(nums) <= 10000`",
"tags": ["stacks", "beginner"]
},
{
"slug": "queue-front-after-dequeues",
"title": "Queue Front After Dequeues",
"module": "data-structures",
"statement": "A **queue** is a linear data structure that follows the **First-In, First-Out (FIFO)** principle. The earliest element added to the queue is always the first one removed.\n\nIn this challenge, your task is to determine which value remains at the **front of the queue** after performing a specified number of dequeue operations.\n\nThe input consists of a list representing values enqueued into an initially empty queue and an integer indicating how many dequeue operations are performed afterward.\n\nYour function should return the value currently at the **front** of the queue.\n\nIf the queue becomes empty after the dequeue operations, return **`-1`**.\n\nThis exercise reinforces several important programming concepts:\n\n* Understanding the **First-In, First-Out (FIFO)** behavior of queues.\n* Simulating queue operations.\n* Accessing elements after removing items from the front.\n* Handling situations where a data structure becomes **empty**.\n\nQueues are widely used in scheduling systems, operating systems, networking, task processing, simulations, and many other real-world applications.",
"original_statement": "A **queue** is a linear data structure that follows the **First-In, First-Out (FIFO)** principle. The earliest element added to the queue is always the first one removed.\n\nIn this challenge, your task is to determine which value remains at the **front of the queue** after performing a specified number of dequeue operations.\n\nThe input consists of a list representing values enqueued into an initially empty queue and an integer indicating how many dequeue operations are performed afterward.\n\nYour function should return the value currently at the **front** of the queue. If the queue becomes empty after the dequeue operations, return **`-1`**.\n\nThis exercise reinforces several important programming concepts:\n\n- Understanding the **First-In, First-Out (FIFO)** behavior of queues.\n- Simulating queue operations.\n- Accessing elements after removing items from the front.\n- Handling situations where a data structure becomes **empty**.\n\nQueues are widely used in scheduling systems, operating systems, networking, task processing, simulations, and many other real-world applications.",
"func_name": "QueueFront",
"return_type": "int",
"param_types": ["[]int", "int"],
"param_names": [],
"hints": ["Each **dequeue** removes exactly **one element** from the front of the queue.", "After removing `dequeues` elements, the new front is the element at that position in the original list.", "If all elements have been removed, return **`-1`**."],
"difficulty": 1,
"xp_reward": 70,
"constraints": "- `0 <= len(nums) <= 10000`\r\n- `0 <= dequeues <= 10000`",
"tags": ["queues", "beginner"]
},
{
"slug": "valid-parentheses",
"title": "Valid Parentheses",
"module": "data-structures",
"statement": "Parentheses, brackets, and braces are commonly used to group expressions and represent nested structures in programming languages, mathematical notation, and markup formats. Ensuring that these symbols are **properly matched** is a fundamental problem in parsing and syntax validation.\n\nIn this challenge, your task is to determine whether a string containing only parentheses, square brackets, and curly braces is **valid**.\n\nA string is considered valid if every **opening bracket** is closed by the **same type** of bracket, and every pair of brackets is closed in the **correct nested order**.\n\nYour function should return **`true`** if the entire string is valid, or **`false`** otherwise.\n\nThis exercise reinforces several important programming concepts:\n\n* Using a **stack** to track nested structures.\n* Matching pairs of opening and closing symbols.\n* Processing strings one character at a time.\n* Validating structured input.\n\nBracket matching is a core algorithm used in compilers, code editors, syntax highlighters, interpreters, expression evaluators, and many other software systems.",
"original_statement": "Parentheses, brackets, and braces are commonly used to group expressions and represent nested structures in programming languages, mathematical notation, and markup formats. Ensuring that these symbols are **properly matched** is a fundamental problem in parsing and syntax validation.\n\nIn this challenge, your task is to determine whether a string containing only **parentheses**, **square brackets**, and **curly braces** is **valid**.\n\nA string is considered valid if every **opening bracket** is closed by the **same type** of bracket, and every pair of brackets is closed in the **correct order**.\n\nYour function should return **`true`** if the entire string is valid, or **`false`** otherwise.\n\nThis exercise reinforces several important programming concepts:\n\n- Using a **stack** to track nested structures.\n- Matching pairs of opening and closing symbols.\n- Processing strings one character at a time.\n- Validating structured input.\n\nBracket matching is a core algorithm used in compilers, code editors, syntax highlighters, interpreters, expression evaluators, and many other software systems.",
"func_name": "ValidParentheses",
"return_type": "bool",
"param_types": ["string"],
"param_names": [],
"hints": ["Push every **opening bracket** onto a stack as you encounter it.", "When you reach a **closing bracket**, it must match the bracket currently on the **top of the stack**.", "After processing the entire string, the stack must be **empty** for the string to be valid."],
"difficulty": 1,
"xp_reward": 70,
"constraints": "- `0 <= len(s) <= 10000`\r\n- The string contains only **`(`**, **`)`**, **`[`**, **`]`**, **`{`**, and **`}`**",
"tags": ["stacks", "strings", "beginner"]
},
{
"slug": "simulate-queue-ops",
"title": "Simulate Queue Operations",
"module": "data-structures",
"statement": "A **queue** is a linear data structure that follows the **First-In, First-Out (FIFO)** principle. Elements are added to the **back** of the queue and removed from the **front**, preserving the order in which they were inserted.\n\nIn this challenge, your task is to simulate a sequence of **queue operations**.\n\nEach operation is provided as a string command. An **`enqueue x`** command inserts the integer `x` at the back of the queue, while a **`dequeue`** command removes the element currently at the front of the queue.\n\nProcess every operation in the order given, then return the **final contents** of the queue from front to back.\n\nIf a dequeue operation is performed while the queue is already empty, simply ignore it.\n\nThis exercise reinforces several important programming concepts:\n\n* Understanding the **FIFO** behavior of queues.\n* Simulating operations on a dynamic data structure.\n* Processing commands sequentially.\n* Updating and maintaining the state of a collection.\n\nQueue simulation is widely used in operating systems, scheduling algorithms, networking, event processing, messaging systems, and many other real-world applications.",
"original_statement": "A **queue** is a linear data structure that follows the **First-In, First-Out (FIFO)** principle. Elements are added to the **back** of the queue and removed from the **front**, preserving the order in which they were inserted.\n\nIn this challenge, your task is to simulate a sequence of **queue operations**.\n\nEach operation is provided as a string command. An **`enqueue x`** command inserts the integer `x` at the back of the queue, while a **`dequeue`** command removes the element currently at the front of the queue.\n\nProcess every operation in the order given, then return the **final contents** of the queue from **front to back**.\n\nIf a dequeue operation is performed while the queue is already empty, simply ignore it.\n\nThis exercise reinforces several important programming concepts:\n\n- Understanding the **FIFO** behavior of queues.\n- Simulating operations on a dynamic data structure.\n- Processing commands sequentially.\n- Updating and maintaining the state of a collection.\n\nQueue simulation is widely used in operating systems, scheduling algorithms, networking, event processing, messaging systems, and many other real-world applications.",
"func_name": "SimulateQueueOperations",
"return_type": "[]int",
"param_types": ["[]string"],
"param_names": [],
"hints": ["Process each operation **one at a time**, updating the queue after every command.", "An **`enqueue x`** operation appends `x` to the **back** of the queue, while **`dequeue`** removes the element at the **front**.", "Attempting to dequeue from an **empty queue** should have **no effect**."],
"difficulty": 2,
"xp_reward": 110,
"constraints": "- `0 <= len(ops) <= 10000`\r\n- Each operation is either **`enqueue x`** or **`dequeue`**",
"tags": ["queues"]
},
{
"slug": "reverse-linked-list-array",
"title": "Reverse a Linked List",
"module": "data-structures",
"statement": "A **linked list** stores its elements as a sequence of connected nodes, where each node points to the next one in the chain. Reversing this sequence is one of the most fundamental operations performed on linked lists and serves as the foundation for many more advanced algorithms.\n\nIn this challenge, your task is to **reverse the order** of a linked list.\n\nFor simplicity, the linked list is represented as a list of values in **head-to-tail order**, rather than as individual linked nodes. Your goal is to produce a new sequence representing how the list would appear after every connection has been reversed.\n\nYour function should return the values of the linked list in **reverse traversal order**.\n\nThis exercise reinforces several important programming concepts:\n\n* Understanding the structure of **linked lists**.\n* Reversing the order of a sequence.\n* Building a new collection from existing data.\n* Solving a classic data structure problem.\n\nLinked list reversal is one of the most common interview questions and is widely used in memory management, data processing, recursive algorithms, and many other software engineering applications.",
"original_statement": "A **linked list** stores its elements as a sequence of connected nodes, where each node points to the next one in the chain. Reversing this sequence is one of the most fundamental operations performed on linked lists and serves as the foundation for many more advanced algorithms.\n\nIn this challenge, your task is to reverse the order of a linked list.\n\nFor simplicity, the linked list is represented as a list of values in **head-to-tail order**, rather than as linked nodes. Your goal is to produce a new sequence representing how the list would appear after every connection has been reversed.\n\nYour function should return the values of the linked list in **reverse traversal order**.\n\nThis exercise reinforces several important programming concepts:\n\n- Understanding the structure of **linked lists**.\n- Reversing the order of a sequence.\n- Building a new collection from existing data.\n- Solving a classic data structure problem.\n\nLinked list reversal is one of the most common interview questions and is widely used in memory management, data processing, recursive algorithms, and many other software engineering applications.",
"func_name": "ReverseLinkedList",
"return_type": "[]int",
"param_types": ["[]int"],
"param_names": [],
"hints": ["The list is provided as values in **head-to-tail order**, so reversing the traversal simply reverses the order of the values.", "You can build a new list by iterating from the **end** toward the beginning.", "An **empty list** remains empty after reversal."],
"difficulty": 2,
"xp_reward": 110,
"constraints": "- `0 <= len(nums) <= 10000`",
"tags": ["linked-lists"]
},
{
"slug": "remove-dup-linked-list",
"title": "Remove Duplicates from Sorted Linked List",
"module": "data-structures",
"statement": "A **sorted linked list** stores its values in non-decreasing order, which means any duplicate values always appear next to one another. This property allows duplicates to be removed efficiently in a single traversal.\n\nIn this challenge, your task is to remove every duplicate value from a **sorted linked list**, ensuring that each distinct value appears exactly once.\n\nFor simplicity, the linked list is represented as a list of values in **head-to-tail order**.\n\nYour function should return a new list containing the values of the linked list after all duplicates have been removed.\n\nThis exercise reinforces several important programming concepts:\n\n* Working with **sorted linked lists**.\n* Identifying **adjacent duplicate** values.\n* Building a new collection while preserving the original order.\n* Traversing data efficiently in a **single pass**.\n\nRemoving duplicates from sorted data is a common operation in database systems, search indexing, data cleaning, and many other real-world applications.",
"original_statement": "A **sorted linked list** stores its values in **non-decreasing order**, which means any duplicate values always appear **next to one another**. This property allows duplicate values to be removed efficiently in a single traversal.\n\nIn this challenge, your task is to remove every duplicate value from a **sorted linked list**, ensuring that each distinct value appears **exactly once**.\n\nFor simplicity, the linked list is represented as a list of values in **head-to-tail order**.\n\nYour function should return a **new list** containing the values of the linked list after all duplicates have been removed.\n\nThis exercise reinforces several important programming concepts:\n\n- Working with **sorted linked lists**.\n- Identifying **adjacent duplicate** values.\n- Building a new collection while preserving the original order.\n- Traversing data efficiently in a **single pass**.\n\nRemoving duplicates from sorted data is a common operation in database systems, search indexing, data cleaning, and many other real-world applications.",
"func_name": "RemoveDuplicatesFromLinkedList",
"return_type": "[]int",
"param_types": ["[]int"],
"param_names": [],
"hints": ["Because the list is **sorted**, duplicate values always appear **consecutively**.", "Keep the **first occurrence** of each value and skip every identical value that follows.", "Traverse the list once while building the resulting collection."],
"difficulty": 2,
"xp_reward": 110,
"constraints": "- `0 <= len(nums) <= 10000`\r\n- `nums` is sorted in **non-decreasing order**",
"tags": ["linked-lists"]
},
{
"slug": "middle-element",
"title": "Middle of a Linked List",
"module": "data-structures",
"statement": "A **linked list** is a linear data structure where each node points to the next node in the sequence. Unlike arrays, linked lists do not provide direct access by index, making certain traversal techniques especially valuable.\n\nIn this challenge, your task is to find the **middle node** of a linked list.\n\nFor simplicity, the linked list is represented as a list of values in **head-to-tail order**. If the list contains an odd number of nodes, return the value of the single middle node. If the list contains an **even number** of nodes, return the value of the **second middle node**.\n\nYour function should return the value stored in the required middle node.\n\nThis exercise reinforces several important programming concepts:\n\n* Understanding the structure of **linked lists**.\n* Applying the **slow and fast pointer** technique.\n* Traversing a sequence efficiently in a **single pass**.\n* Solving position-based problems without relying on indexing.\n\nFinding the middle of a linked list is a classic interview problem and is widely used in linked list algorithms, cycle detection, recursive splitting, and merge sort implementations.",
"original_statement": "A **linked list** is a linear data structure where each node points to the next node in the sequence. Unlike arrays, linked lists do not provide direct access by index, making certain traversal techniques especially valuable.\n\nIn this challenge, your task is to find the **middle node** of a linked list.\n\nFor simplicity, the linked list is represented as a list of values in **head-to-tail order**. If the list contains an **odd number** of nodes, return the value of the single middle node. If the list contains an **even number** of nodes, return the value of the **second** middle node.\n\nYour function should return the value stored in the required middle node.\n\nThis exercise reinforces several important programming concepts:\n\n- Understanding the structure of **linked lists**.\n- Applying the **slow and fast pointer** technique.\n- Traversing a sequence efficiently in a **single pass**.\n- Solving position-based problems without relying on indexing.\n\nFinding the middle of a linked list is a classic interview problem and is widely used in linked list algorithms, cycle detection, recursive splitting, and merge sort implementations.",
"func_name": "MiddleElement",
"return_type": "int",
"param_types": ["[]int"],
"param_names": [],
"hints": ["Move a **slow pointer** one step at a time while moving a **fast pointer** two steps at a time.", "When the fast pointer reaches the end of the list, the slow pointer will be positioned at the **middle**.", "For an **even-length** list, this technique naturally lands on the **second middle** node."],
"difficulty": 3,
"xp_reward": 150,
"constraints": "- `1 <= len(nums) <= 10000`",
"tags": ["linked-lists", "two-pointers"]
},
{
"slug": "has-cycle",
"title": "Linked List Cycle Detection",
"module": "data-structures",
"statement": "A **linked list** is a sequence of nodes where each node points to the next one in the chain. Normally, following these links eventually reaches the end of the list. However, an incorrect connection can cause the list to loop back to an earlier node, creating a **cycle** that can result in infinite traversal.\n\nIn this challenge, your task is to determine whether a linked list contains a **cycle**.\n\nThe linked list is represented by a **`next`** array, where `next[i]` stores the index of the node that follows node `i`. A value of **`-1`** indicates that the node has no successor and marks the end of the list.\n\nStarting from the given node, determine whether repeatedly following the links eventually revisits a previously visited node.\n\nYour function should return **`true`** if the list contains a cycle, or **`false`** otherwise.\n\nThis exercise reinforces several important programming concepts:\n\n* Understanding the structure of **singly linked lists**.\n* Detecting cycles using the **two-pointer (Floyd's Tortoise and Hare)** technique.\n* Traversing linked structures efficiently.\n* Solving graph-like traversal problems with **constant extra space**.\n\nCycle detection is a fundamental algorithm used in memory management, graph traversal, compiler design, networking, and many other computer science applications.",
"original_statement": "A **linked list** is a sequence of nodes where each node points to the next one in the chain. Normally, following these links eventually reaches the end of the list. However, an incorrect connection can cause the list to **loop back** to an earlier node, creating a **cycle** that can result in infinite traversal.\n\nIn this challenge, your task is to determine whether a linked list contains a **cycle**.\n\nThe linked list is represented by a **`next` array**, where `next[i]` stores the index of the node that follows node `i`. A value of **`-1`** indicates that the node has no successor and marks the end of the list.\n\nStarting from the given node, determine whether repeatedly following the links eventually revisits a previously visited node.\n\nYour function should return **`true`** if the list contains a cycle, or **`false`** otherwise.\n\nThis exercise reinforces several important programming concepts:\n\n- Understanding the structure of **singly linked lists**.\n- Detecting cycles using the **two-pointer (Floyd's Tortoise and Hare)** technique.\n- Traversing linked structures efficiently.\n- Solving graph-like traversal problems with **constant extra space**.\n\nCycle detection is a fundamental algorithm used in memory management, graph traversal, compiler design, networking, and many other computer science applications.",
"func_name": "HasCycle",
"return_type": "bool",
"param_types": ["[]int", "int"],
"param_names": [],
"hints": ["**Floyd's Tortoise and Hare** algorithm uses two pointers that move at different speeds.", "If the **fast pointer** ever catches the **slow pointer**, the linked list contains a cycle.", "A value of **`-1`** represents the end of the list. Reaching it means no cycle exists."],
"difficulty": 3,
"xp_reward": 150,
"constraints": "- `0 <= len(next) <= 10000`\r\n- `-1 <= next[i] < len(next)`\r\n- `0 <= start < len(next)`, unless the list is empty",
"tags": ["linked-lists", "two-pointers"]
},
{
"slug": "binary-search",
"title": "Binary Search",
"module": "data-structures",
"statement": "Searching through a **sorted collection** one element at a time works, but it becomes increasingly inefficient as the collection grows. **Binary search** improves performance by repeatedly dividing the search space in half, allowing it to locate a target value in **O(log n)** time.\n\nIn this challenge, your task is to search for a **target integer** within a **sorted list** of integers.\n\nBegin by examining the middle element of the current search range. If it matches the target, return its **index**. Otherwise, eliminate the half of the list that cannot possibly contain the target, then continue searching the remaining half.\n\nIf the target value does not exist in the list, your function should return **`-1`**.\n\nThis exercise reinforces several important programming concepts:\n\n* Working with **sorted collections**.\n* Applying the **divide-and-conquer** strategy.\n* Maintaining left and right search boundaries.\n* Performing efficient searches with **logarithmic time complexity**.\n\nBinary search is one of the most fundamental algorithms in computer science and serves as the foundation for efficient searching, database indexing, lookup tables, and many other high-performance applications.",
"original_statement": "Searching through a **sorted collection** one element at a time works, but it becomes increasingly inefficient as the collection grows. **Binary search** improves performance by repeatedly dividing the search space in half, allowing it to locate a target value in **O(log n)** time.\n\nIn this challenge, your task is to search for a **target integer** within a **sorted list** of integers.\n\nBegin by examining the middle element of the current search range. If it matches the target, return its **index**. Otherwise, eliminate the half of the list that cannot possibly contain the target, then continue searching the remaining half.\n\nIf the target value does not exist in the list, your function should return **`-1`**.\n\nThis exercise reinforces several important programming concepts:\n\n- Working with **sorted collections**.\n- Applying the **divide-and-conquer** strategy.\n- Maintaining **left** and **right** search boundaries.\n- Performing efficient searches with **logarithmic time complexity**.\n\nBinary search is one of the most fundamental algorithms in computer science and serves as the foundation for efficient searching, database indexing, lookup tables, and many other high-performance applications.",
"func_name": "BinarySearch",
"return_type": "int",
"param_types": ["[]int", "int"],
"param_names": [],
"hints": ["Binary search only works on a **sorted** collection—always assume or verify this prerequisite.", "Compare the target with the **middle element**, then continue searching only the half where the target could still exist.", "Stop when the search boundaries cross. If the target was never found, return **`-1`**."],
"difficulty": 3,
"xp_reward": 150,
"constraints": "- `0 <= len(nums) <= 100000`\r\n- `nums` is sorted in **non-decreasing order**",
"tags": ["algorithms", "searching"]
},
{
"slug": "evaluate-postfix",
"title": "Evaluate Postfix Expression",
"module": "data-structures",
"statement": "**Postfix notation**, also known as **Reverse Polish Notation (RPN)**, represents arithmetic expressions without parentheses by placing every operator after its operands. This notation is commonly evaluated using a **stack**.\n\nIn this challenge, your task is to evaluate a postfix expression represented as a list of tokens.\n\nEach token is either an **integer** or one of the arithmetic operators **`+`**, **`-`**, **`*`**, or **`/`**.\n\nProcess the tokens from left to right, using a stack to temporarily store operands until an operator is encountered. When processing division, the result should **truncate toward zero**, matching standard integer division behavior.\n\nYour function should return the final value of the evaluated expression.\n\nThis exercise reinforces several important programming concepts:\n\n* Using a **stack** to process data.\n* Evaluating expressions one token at a time.\n* Applying arithmetic operators in the correct order.\n* Understanding an alternative expression format used by calculators and compilers.\n\nPostfix evaluation is a classic application of stacks and is widely used in expression parsing, compiler design, virtual machines, and calculator implementations.",
"original_statement": "**Postfix notation**, also known as **Reverse Polish Notation (RPN)**, represents arithmetic expressions without parentheses by placing every operator **after** its operands. This notation is commonly evaluated using a **stack**.\n\nIn this challenge, your task is to evaluate a postfix expression represented as a list of **tokens**.\n\nEach token is either an **integer** or one of the arithmetic operators **`+`**, **`-`**, **`*`**, or **`/`**.\n\nProcess the tokens from left to right, using a stack to temporarily store operands until an operator is encountered. When processing division, the result should **truncate toward zero**, matching standard integer division behavior.\n\nYour function should return the final value of the evaluated expression.\n\nThis exercise reinforces several important programming concepts:\n\n- Using a **stack** to process data.\n- Evaluating expressions one token at a time.\n- Applying arithmetic operators in the correct order.\n- Understanding an alternative expression format used by calculators and compilers.\n\nPostfix evaluation is a classic application of stacks and is widely used in expression parsing, compiler design, virtual machines, and calculator implementations.",
"func_name": "EvaluatePostfix",
"return_type": "int",
"param_types": ["[]string"],
"param_names": [],
"hints": ["Scan the tokens from **left to right**, pushing every number onto a stack.", "When an operator is encountered, pop the **top two values**, apply the operator, then push the result back.", "For **subtraction** and **division**, remember that the **second value popped** is the left operand."],
"difficulty": 4,
"xp_reward": 190,
"constraints": "- `1 <= len(tokens) <= 1000`\r\n- The expression is always **valid** and **well-formed**",
"tags": ["stacks", "algorithms"]
},
{
"slug": "merge-sorted-lists",
"title": "Merge Two Sorted Linked Lists",
"module": "data-structures",
"statement": "Merging two **sorted sequences** into a single sorted result is one of the most fundamental operations in computer science. It serves as the foundation of algorithms such as **Merge Sort** and is widely used when combining already ordered data.\n\nIn this challenge, your task is to merge two **sorted linked lists** into one sorted sequence.\n\nFor simplicity, each linked list is represented as a list of values in **head-to-tail order** rather than as individual linked nodes.\n\nRepeatedly compare the current front element of each list, append the smaller value to the result, and continue until all elements have been merged.\n\nYour function should return a new sorted list containing every element from both input lists.\n\nThis exercise reinforces several important programming concepts:\n\n* Working with **sorted data**.\n* Comparing values from multiple collections.\n* Building a new collection incrementally.\n* Applying the **two-pointer** technique.\n\nMerging sorted sequences is a fundamental operation used in sorting algorithms, database systems, search engines, and large-scale data processing pipelines.",
"original_statement": "Merging two **sorted sequences** into a single sorted result is one of the most fundamental operations in computer science. It serves as the foundation of algorithms such as **Merge Sort** and is widely used when combining already ordered data.\n\nIn this challenge, your task is to merge two **sorted linked lists** into one sorted sequence.\n\nFor simplicity, each linked list is represented as a list of values in **head-to-tail order** rather than as individual linked nodes.\n\nRepeatedly compare the current front element of each list, append the smaller value to the result, and continue until all elements have been merged.\n\nYour function should return a **new sorted list** containing every element from both input lists.\n\nThis exercise reinforces several important programming concepts:\n\n- Working with **sorted data**.\n- Comparing values from multiple collections.\n- Building a new collection incrementally.\n- Applying the **two-pointer** technique.\n\nMerging sorted sequences is a fundamental operation used in sorting algorithms, database systems, search engines, and large-scale data processing pipelines.",
"func_name": "MergeSortedLists",
"return_type": "[]int",
"param_types": ["[]int", "[]int"],
"param_names": [],
"hints": ["Maintain one pointer for **each list**, comparing the current elements at every step.", "Append the **smaller value** to the result, then advance only the pointer for the list that supplied it.", "Once one list is exhausted, append all remaining elements from the other list."],
"difficulty": 4,
"xp_reward": 190,
"constraints": "- `0 <= len(a), len(b) <= 10000`",
"tags": ["linked-lists", "two-pointers"]
},
{
"slug": "kth-largest",
"title": "Kth Largest Element",
"module": "data-structures",
"statement": "Finding the **largest** value in a collection is straightforward, but many practical applications require finding the **k-th largest** element instead. This problem appears frequently in ranking systems, leaderboards, statistics, and priority queues.\n\nIn this challenge, your task is to determine the **k-th largest element** in a list of integers.\n\nThe **1st largest** element is the maximum value in the list, the **2nd largest** is the next highest value, and so on.\n\nYour function should return the value that occupies the requested ranking.\n\nThis exercise reinforces several important programming concepts:\n\n* Working with **ordered rankings**.\n* Processing collections of data.\n* Understanding the relationship between **sorting** and element selection.\n* Solving selection problems commonly encountered in technical interviews.\n\nFinding the k-th largest element is a common operation in data analysis, search systems, scheduling algorithms, and priority queue implementations.",
"original_statement": "Finding the **largest** value in a collection is straightforward, but many practical applications require finding the **k-th largest** element instead. This problem appears frequently in ranking systems, leaderboards, statistics, and priority queues.\n\nIn this challenge, your task is to determine the **k-th largest element** in a list of integers.\n\nThe **1st largest** element is the maximum value in the list, the **2nd largest** is the next highest value, and so on.\n\nYour function should return the value that occupies the requested ranking.\n\nThis exercise reinforces several important programming concepts:\n\n- Working with **ordered rankings**.\n- Processing collections of data.\n- Understanding the relationship between **sorting** and element selection.\n- Solving selection problems commonly encountered in technical interviews.\n\nFinding the k-th largest element is a common operation in data analysis, search systems, scheduling algorithms, and priority queue implementations.",
"func_name": "KthLargest",
"return_type": "int",
"param_types": ["[]int", "int"],
"param_names": [],
"hints": ["If the list were sorted in **descending order**, the answer would appear at index **`k - 1`**.", "Sorting provides the simplest correct solution, although more advanced approaches can achieve better performance.", "**`k`** is always guaranteed to be within the valid range of the list."],
"difficulty": 4,
"xp_reward": 190,
"constraints": "- `1 <= k <= len(nums) <= 10000`",
"tags": ["algorithms", "sorting"]
},
{
"slug": "is-balanced-tree",
"title": "Balanced Binary Tree",
"module": "data-structures",
"statement": "A **binary tree** organizes data in a hierarchical structure where each node can have at most two children. Many tree algorithms perform best when the tree remains **balanced**, meaning neither side grows significantly deeper than the other.\n\nIn this challenge, your task is to determine whether a binary tree is **height-balanced**.\n\nThe tree is represented as a **level-order array**, where the root is stored at index `0`, the left child of node `i` is located at `2i + 1`, and the right child is located at `2i + 2`. A value of **`-1`** represents a missing node.\n\nA binary tree is considered balanced if, for every node, the heights of its left and right subtrees differ by **no more than one**.\n\nYour function should return **`true`** if the tree is balanced, or **`false`** otherwise.\n\nThis exercise reinforces several important programming concepts:\n\n* Working with **binary tree** representations.\n* Computing the **height** of recursive structures.\n* Applying **recursive divide-and-conquer** techniques.\n* Detecting structural imbalances efficiently.\n\nBalanced tree checking is a core operation used in search trees, databases, indexing systems, compiler implementations, and many other performance-critical applications.",
"original_statement": "A **binary tree** organizes data in a hierarchical structure where each node can have at most **two children**. Many tree algorithms perform best when the tree remains **balanced**, meaning neither side grows significantly deeper than the other.\n\nIn this challenge, your task is to determine whether a binary tree is **height-balanced**.\n\nThe tree is represented as a **level-order array**, where the root is stored at index `0`, the left child of node `i` is located at `2i + 1`, and the right child is located at `2i + 2`. A value of **`-1`** represents a missing node.\n\nA binary tree is considered balanced if, for **every node**, the heights of its left and right subtrees differ by **no more than one**.\n\nYour function should return **`true`** if the tree is balanced, or **`false`** otherwise.\n\nThis exercise reinforces several important programming concepts:\n\n- Working with **binary tree** representations.\n- Computing the **height** of recursive structures.\n- Applying **recursive divide-and-conquer** techniques.\n- Detecting structural imbalances efficiently.\n\nBalanced tree checking is a core operation used in search trees, databases, indexing systems, compiler implementations, and many other performance-critical applications.",
"func_name": "IsBalancedTree",
"return_type": "bool",
"param_types": ["[]int"],
"param_names": [],
"hints": ["The tree uses a **level-order representation**, where each node's children are found at predictable indices.", "Recursively compute the height of each subtree while checking whether their height difference exceeds **1**.", "Returning a special sentinel value (such as **`-1`**) when an imbalance is detected allows the recursion to terminate early."],
"difficulty": 5,
"xp_reward": 220,
"constraints": "- `0 <= len(nodes) <= 1000`\r\n- `nodes[0] == -1` represents an **empty tree**, which is considered balanced",
"tags": ["trees", "recursion"]
},
{
"slug": "count-words-with-prefix",
"title": "Count Words With Prefix",
"module": "data-structures",
"statement": "Many search systems organize words based on their **prefixes**, making it possible to quickly find every word that begins with a particular sequence of characters. This concept forms the basis of the **Trie (Prefix Tree)** data structure.\n\nIn this challenge, your task is to count how many words in a list begin with a specified **prefix**.\n\nExamine each word and determine whether its opening characters match the given prefix. Count every matching word and return the total.\n\nThis exercise reinforces several important programming concepts:\n\n* Working with **collections of strings**.\n* Comparing **prefixes** within text.\n* Iterating through a list while maintaining a **running count**.\n* Understanding the practical motivation behind **Trie (Prefix Tree)** data structures.\n\nPrefix searching is widely used in autocomplete systems, search engines, dictionaries, command-line tools, and many other text-processing applications.",
"original_statement": "Many search systems organize words based on their **prefixes**, making it possible to quickly find every word that begins with a particular sequence of characters. This concept forms the basis of the **Trie (Prefix Tree)** data structure.\n\nIn this challenge, your task is to count how many words in a list begin with a specified **prefix**.\n\nExamine each word and determine whether its opening characters match the given prefix. Count every matching word and return the total.\n\nThis exercise reinforces several important programming concepts:\n\n- Working with **collections of strings**.\n- Comparing **prefixes** within text.\n- Iterating through a list while maintaining a **running count**.\n- Understanding the practical motivation behind **Trie (Prefix Tree)** data structures.\n\nPrefix searching is widely used in autocomplete systems, search engines, dictionaries, command-line tools, and many other text-processing applications.",
"func_name": "CountWordsWithPrefix",
"return_type": "int",
"param_types": ["[]string", "string"],
"param_names": [],
"hints": ["A **Trie** stores words so that all words sharing a prefix also share the same path.", "You do **not** need to build a Trie to solve this challenge—a direct prefix comparison for each word is sufficient.", "Increment your counter whenever a word begins with the specified prefix."],
"difficulty": 5,
"xp_reward": 220,
"constraints": "- `0 <= len(words) <= 10000`\r\n- `0 <= len(prefix) <= 100`",
"tags": ["tries", "strings"]
},
{
"slug": "count-connected-components",
"title": "Count Connected Components in a Graph",
"module": "data-structures",
"statement": "A **graph** consists of a collection of nodes connected by edges. Not every node must be connected to every other node, meaning a graph may be divided into multiple independent groups known as **connected components**.\n\nIn this challenge, your task is to determine how many **connected components** exist in an **undirected graph**.\n\nThe graph contains **`n` nodes**, labeled from `0` to `n-1`, and its edges are provided as a flattened list where every consecutive pair of values represents a connection between two nodes.\n\nYour function should return the total number of separate connected groups within the graph.\n\nThis exercise reinforces several important programming concepts:\n\n* Working with **graph data structures**.\n* Understanding **connected components**.\n* Grouping related nodes using the **Union-Find (Disjoint Set Union)** data structure.\n* Efficiently merging and querying connected groups.\n\nConnected component detection is widely used in networking, social graphs, image processing, clustering algorithms, and many other real-world applications.",
"original_statement": "A **graph** consists of a collection of **nodes** connected by **edges**. Not every node must be connected to every other node, meaning a graph may be divided into multiple independent groups known as **connected components**.\n\nIn this challenge, your task is to determine how many **connected components** exist in an **undirected graph**.\n\nThe graph contains **`n` nodes**, labeled from **`0`** to **`n-1`**, and its edges are provided as a flattened list where every consecutive pair of values represents a connection between two nodes.\n\nYour function should return the total number of separate connected groups within the graph.\n\nThis exercise reinforces several important programming concepts:\n\n- Working with **graph data structures**.\n- Understanding **connected components**.\n- Grouping related nodes using the **Union-Find (Disjoint Set Union)** data structure.\n- Efficiently merging and querying connected groups.\n\nConnected component detection is widely used in networking, social graphs, image processing, clustering algorithms, and many other real-world applications.",
"func_name": "CountComponents",
"return_type": "int",
"param_types": ["int", "[]int"],
"param_names": [],
"hints": ["**Union-Find (Disjoint Set Union)** efficiently merges nodes that belong to the same connected component.", "Each edge is represented by **two consecutive values** in the flattened `edges` list.", "After processing every edge, count the number of **distinct root parents** to determine the number of connected components."],
"difficulty": 5,
"xp_reward": 220,
"constraints": "- `0 <= n <= 1000`\r\n- `len(edges)` is always **even**\r\n- `0 <= edges[i] < n`",
"tags": ["graphs", "union-find"]
}
]