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...

Read

November 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...

Read

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...

Read

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...

Read

November 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...

Read

November 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...

Read

November 16, 2022

Construct binary search tree from preorder traversal

As preorder traversal is given, we know the first element will be the root. We will create a function witg a bound the maximum number it will handle. The left recursion will take the elements smaller...

Read

November 16, 2022

Count days spent together

We will use a helper function to get the number of days from the beginning of the year to the given date. Then take the maximum of arrival date and minimum of departure date and subtract the minimum...

Read

November 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

November 16, 2022

Insert into a binary search tree

We will use DFS for inserting. We recursively insert the left and right subtrees and then return the root. If the root is null, we return the new node. If the root is greater than the value, we...

Read
... 35 36 37 38 39 ...