LeetCode - 150 - Daily Temperatures

The problem Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead. Examples Input: temperatures = [73,74,75,71,69,72,76,73] Output: [1,1,4,2,1,1,0,0] Input: temperatures = [30,40,50,60] Output: [1,1,1,0] Input: temperatures = [30,60,90] Output: [1,1,0] Constraints 1 <= temperatures.length <= 10^5 30 <= temperatures[i] <= 100 Explanation Before we jump to the solution, let’s figure out the way we can solve this problem. In the first example, we can see that we can calculate how many days in the input array it takes us to find a temperature that is greater than 73. ...

June 12, 2025 · 3 min · Dmytro Chumakov

LeetCode - 150 - Generate Parentheses

The problem Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Examples Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Input: n = 1 Output: ["()"] Constraints 1 <= n <= 8 Explanation Before we jump to the solution, let’s figure out what well-formed parentheses mean. In this problem, this means when you’re writing the code using nested parentheses, you want them to be nested in a valid way, like (()()). ...

June 9, 2025 · 2 min · Dmytro Chumakov

LeetCode - 150 - Evaluate Reverse Polish Notation

The problem You are given an array of strings tokens that represents an arithmetic expression in Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. Note that: The valid operators are +, -, * and /. Each operand may be an integer or another expression. The division between two integers always truncates toward zero. There will not be any division by zero. The input represents a valid arithmetic expression in reverse Polish notation. The answer and all the intermediate calculations can be represented in a 32-bit integer. Examples Input: tokens = ["2","1","+","3","*"] Output: 9 Explanation: ((2 + 1) * 3) = 9 Input: tokens = ["4","13","5","/","+"] Output: 6 Explanation: (4 + (13 / 5)) = 6 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]. Explanation Let’s take a look at the example with input tokens = ["2","1","+","3","*"], and try to figure out the way we can solve it. ...

June 5, 2025 · 3 min · Dmytro Chumakov

LeetCode - 150 - Min Stack

The problem Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() initializes the stack object. void push(int val) pushes the element val onto the stack. void pop() removes the element on the top of the stack. int top() gets the top element of the stack. int getMin() retrieves the minimum element in the stack. You must implement a solution with O(1) time complexity for each function. ...

June 3, 2025 · 3 min · Dmytro Chumakov

LeetCode - 150 - Sliding Window Maximum

The problem You are given an array of integers nums, and there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window. Examples Input: nums = [1,3,-1,-3,5,3,6,7], k = 3 Output: [3,3,5,5,6,7] Explanation: Window position Max --------------- ----- [1 3 -1] -3 5 3 6 7 3 1 [3 -1 -3] 5 3 6 7 3 1 3 [-1 -3 5] 3 6 7 5 1 3 -1 [-3 5 3] 6 7 5 1 3 -1 -3 [5 3 6] 7 6 1 3 -1 -3 5 [3 6 7] 7 Input: nums = [1], k = 1 Output: [1] Constraints 1 <= nums.length <= 10^5 -10^4 <= nums[i] <= 10^4 1 <= k <= nums.length Explanation Before we jump into the solution, let’s look at our example with nums = [1,3,-1,-3,5,3,6,7], k = 3 We can see that at the first position we have max value 3, which we add to our output array. ...

June 2, 2025 · 4 min · Dmytro Chumakov