Problems


January 13, 2023

Number of good binary strings

We will solve it using top-down dynamic programming. We will create a helper function dp that will return the number of good binary strings of length n and ending with end....

Read

January 13, 2023

Longest path with different adjacent characters

We will create a tree from the edges list. Then we will start DFS from starting node 0. Then we will calculate the longest path in the subtree of each node. Finally we will return the...

Read

January 12, 2023

Number of nodes in the sub tree with the same label

We will create a tree from the edges list. Then we will start DFS from starting node 0. Then we will calculate all the nodes in the subtree of each node. Finally we will return the...

Read

January 11, 2023

Minimum time to collect all apples in a tree

We will create a graph form the edges. Then we will start from node 0, and run DFS to visit all the apples and count the number of edges on the way. Finally we will return the maximum number of...

Read

January 11, 2023

Maximum binary string after change

We will use greedy approach to solve the problem. We will find the first 0 and change it to 1. Then we will find the next 0 and change it to 1. We...

Read

January 11, 2023

Maximum number of points with cost

We will use top-down approach to solve the problem. We will calculate the maximum points for each cell. Then we will return the maximum points in the last row. Time complexity: O(mn)...

Read

January 10, 2023

Find good days to rob the bank

We will calculate the prefix sum and postfix sum of the securities. Then we iterate form time till securities-time, check the prefix and postfix sum for the given condition, if the satify, we add...

Read

January 10, 2023

Shuffle the array

We will iterate over the half of of the array and add the elements to the result array form the front and middle. Time complexity: O(n) Space complexity: O(1)

Read

January 9, 2023

Find and replace in string

We will initialize the string as a character array. Then create a replacement map using the provided source, indices and target. Then we iterate over this map, and replace the characters. Finally...

Read

January 9, 2023

Maximal score after applying k operations

We will use a heap to keep track of the maximum score. We will pop the maximum score from the heap and apply the operations to the popped score. We will push the new scores to the heap. We will...

Read
... 7 8 9 10 11 ...