Problems
November 18, 2022
Linked list components
We will create a hashset with the nums. Then we will traverse the linked list and check if the current node is in the hashset. If yes, that means both are connected. We will then traverse the linked...
ReadNovember 17, 2022
Find the highest altitude
We will iterate over the gain array and add the gain to the current altitude. We will update the maximum altitude if the current altitude is greater than the maximum altitude. We can also achieve...
ReadNovember 17, 2022
Rectangle area
We will find the area of the first rectangle and the second rectangle. We will find the area of the overlapping rectangle by finding the length and breadth of the overlapping rectangle. We will...
ReadNovember 17, 2022
Symmetric tree
We will create a function isMirror
which will take two nodes as input. If both the nodes are None
, we will return True
. If one of the nodes is...
November 17, 2022
Number of digit one
We will create a function countDigitOne
which will take a number as input. We will initialize a variable count
to 0
. We will initialize a variable...
November 17, 2022
Finding the users active minutes
We will use a hashset to count the unique logs for each user. Then we iterate over that, take the length of the hashset and add it to the result.
Time complexity: O(n)
Space...
November 16, 2022
Shortest subarray to be removed to make array sorted
We will use two pointers to find the longest subarray that is sorted. The answer will be the length of the array minus the length of the longest subarray.
Time complexity: O(n)
Space...
November 16, 2022
Minimum distance to the target element
We will iterate over all the elements and find the minimum distance.
Time complexity: O(n)
Space complexity: O(1)
November 16, 2022
Minimum time visiting all points
If we go diagonally, we can reach the destination in the minimum time, actually twice as first as moving vertically and horizontally. So, we will find the maximum of the difference between the x and...
ReadNovember 16, 2022
Delete nodes and return forest
We will use DFS for deleting the nodes. We recursively delete the left and right subtrees and then return the root. If the root is in the set, we return the left and right subtrees, and if the root...
Read