Problems
November 22, 2022
Sort colors
We will use two pointers to keep track of the start and end of the array. Then, we will iterate through the array. If the number is 0, then we will swap the number at the start pointer with the...
ReadNovember 22, 2022
Split array largest sum
We binary search largest sum in range [max(nums), sum(nums)], which is left = max(nums), right = sum(nums). mid = left + (right - left) // 2 If canPartition(mid) then: Update the answer so far...
ReadNovember 22, 2022
Random pick index
We will use a dictionary to store the indices of the numbers. Then, we will iterate through the given array and store the indices of the numbers in the dictionary. Then, we will use a random number...
ReadNovember 22, 2022
Shuffle an array
We will use a list to store the original array. Then, we will use a list to store the shuffled array. Then, we will use a random number generator to generate a random number. Then, we will swap the...
ReadNovember 21, 2022
Number of operations to make network connected
We will create an adjacency list of the graph and then we will traverse the graph using DFS and count the number of connected components. If the number of connected components is greater than 1, then...
ReadNovember 21, 2022
Nearest exit from entrance in maze
We will start from the entrance, run BFS through the matrix and find the nearest exit. If we can't find the exit, we will return -1
.
Time complexity: O(mn)
Space...
November 21, 2022
Linked list in binary tree
We will traverse the tree using DFS and check if the linked list is present in the tree or not. If the linked list is present in the tree, then we will return True
. Otherwise, we will...
November 21, 2022
Camelcase matching
We will create a helper function to check if a string is a subsequence of another string. Then we will iterate over the queries and check if the query is a subsequence of the pattern. If it is, then...
ReadNovember 21, 2022
Minimum addition to make integer beautiful
We will iterate through the digits of the number and find the minimum number of digits we need to add to make the number beautiful. We will keep track of the number of digits we have seen and the...
ReadNovember 21, 2022
Maximum sum circular subarray
We will use Kadane's algorithm to find the maximum subarray sum. Then, we will find the minimum subarray sum and subtract it from the total sum of the array. If the total sum is greater than the...
Read