Hello, friends! Today, I have solved four problems on LeetCode, which are Generate Parentheses, 3Sum Closest, Remove K-Digits, and Number of Subarrays with Bounded Maximum. All of these can be solved using different concepts. So by solving at least one problem from each concept, we can recap various concepts in a single day.
The Generate Parentheses problem is solved with a recursive approach. 3Sum Closest is solvable with the two-pointer approach. Remove K-Digits, as a logical problem can be approached by using a stack. Finally, the Number of Subarrays with Bounded Maximum problem can also be solved with a logical approach.
This involves finding all the possible parenthesized arrangements of a given number within the Generate Parentheses problem. Applying recursion here, we go over the process until we hit all possible arrangements. If we hit the input number, we stop.
In the 3Sum Closest problem, we use the two-pointer technique. We initialize the left pointer to zero and the right pointer to the last index. We then traverse with both pointers until we find the sum closest to the target.
We can solve Remove K-Digits using a stack with a logical approach. In this problem, we also have to handle edge cases like leading zeros. In each iteration, we push the smaller digits to the stack and then pop the stack at the end to form the new number.
For the Count of Subarrays with Bounded Maximum, we use a loop from the array to traverse each, compare it with the defined bounds, and then move on to increment the counter. At the end of it all, we are returning the count.
Well, hope my experience helps!!!
Top comments (0)