Problems
August 30, 2022
Remove duplicates from sorted list II
We will have 2 pointers, when we iterate over each node, we check if we found duplicate, then we move right pointer until we hit another value. Then remove all nodes between 2 pointers and move both...
ReadAugust 30, 2022
Furthest building you can reach
We will take the ladders for the longest obstackles. First we take the obstackles in a heap, then take the smallest, if the diff is less than or equals to the bricks, we take the bricks, else we take...
ReadAugust 29, 2022
All paths from source to target
We will always start from 0, so we add 0 in that path. Then we run DFS from 0, and when we find the last node, which is the length of the graph-1 node, we add this current path to our final paths...
ReadAugust 29, 2022
Simplify path
First we will split the the path with /
as delimeter. Then we iterate over the items of the path, if the item is .
or empty, we just ignore it. If the item is anything but...
August 29, 2022
Divide two integers
We will divide the dividend by the divisor and cast it to an integer. If the answer is bigger than 2^31-1, which is the highest value of 32-bit integer, we cap it to the highest 32-bit integer value,...
ReadAugust 29, 2022
Number of islands
We will iterate over the grid, if we found land which is 1, we start dfs from there, and added all the adjacent 1 to the visited set. We will also increase the number of islands for that. When the...
ReadAugust 29, 2022
Remove duplicates from sorted array II
We will iterate over the whole array from index 1 to the end-1, compare the values of 3 consecutive values, if they are same, we change the first element to 10001, as our input can be as big as 10^4....
ReadAugust 29, 2022
Remove duplicates from sorted array
We will iterate over each element from index 1 to the end of the list, if 2 consecutive numbers are equals, we convert the first number to 101, as out input list could have numbers upto 100. Then we...
ReadAugust 29, 2022
Number of provinces
We will iterate over each item in the rows, reach row actually denotes the number of connections one city could have. So, we will run DFS in a given neighbors, and if it is not in the visited set, we...
ReadAugust 29, 2022
Minimum size subarray sum
We will take a sliding window, add it to the sum, if the sum is greater than or equals to the target, we calculate the width of our sliding window and compare with our current result and took the...
Read