Problems


June 4, 2023

Check if it is a straight line

We will check if the slope of the line joining the first two points is equal to the slope of the line joining the second and third points. If it is, then we will check the same for the next two...

Read

June 2, 2023

Time needed to inform all employees

We will start BFS from the manager with no manager. We will keep track of the maximum time taken to inform all the employees. Time complexity: O(n) Space complexity: O(n)

Read

June 1, 2023

Shortest path in binary matrix

We will start BFS from the top left corner of the matrix till we reach the bottom right. Then we will return the shortest path length. Time complexity: O(n) Space complexity:...

Read

May 28, 2023

Vowels of all substrings

We can use bottom-up dynamic programming to solve the problem. We will use a variable vowels to store the number of vowels in the string. Then we will iterate over the string and update...

Read

May 28, 2023

Number of substrings containing all three characters

We can use a sliding window to solve the problem. We will use a variable count to store the number of substrings containing all three characters. Then we will iterate over the string and...

Read

May 27, 2023

Stone game III

We can use top-down dynamic programming to solve the problem. We will use two pointers i and m to iterate over the piles and the number of stones that can be taken...

Read

May 27, 2023

Univalued binary tree

We can use depth-first search to solve the problem. We will use a variable val to store the value of the root node. Then we will recursively check if the value of the current node is...

Read

May 27, 2023

Stone game II

We can use top-down dynamic programming to solve the problem. First we will calculate the suffix sum of the piles. Then we will use two pointers i and m to iterate over the...

Read

May 24, 2023

Left and right sum differences

We will iterate over the array and compute the sum of the left and right subarrays as we iterate through. Then we will compute the difference between the sums and append it to our result. Finally we...

Read

May 24, 2023

Count vowel strings in ranges

We construct alambdaboolean functionvowelsto assess whether the word qualifies. Then we map the words using this function. Then we construct the prefix sum of the mapped words. Finally, we return the...

Read
1 2 3 4 5 ...