Problems


December 3, 2022

Find k length substrings with no repeated characters

We will use a sliding window to solve this problem. The window will be a substring of the input string. The window will be valid if it has no repeated characters. We will keep track of the number of...

Read

December 2, 2022

Connecting cities with minimum cost

We will use Kruskal's algorithm to solve this problem. We will sort the edges in ascending order of their weights. Then we will use Union Find data structure to construct the graph. We will then...

Read

December 2, 2022

Minimum cost to reach city with discounts

We will use Dijkstra's algorithm to solve this problem. We will create a graph with the cities as the nodes and the edges as the roads. We will then use Dijkstra's algorithm to find the shortest path...

Read

December 2, 2022

Determine if two strings are close

We will check if the two strings are equal. If they are not equal, then we will return false. If they are equal, then we will check if the frequency of each character in the two strings are equal. If...

Read

December 2, 2022

Previous permutation with one swap

We will iterate through the array from the end. We will keep track of the index of the first element that is smaller than the previous element. We will then iterate through the array from the end. We...

Read

December 2, 2022

Search in a sorted array of unknown size

We will use binary search to find the index of the target. We will start with the index 1. If the element at the index is smaller than the target, then we will double the index. If the element at the...

Read

December 2, 2022

Nth digit

Integers can be divided into groups 1-9, 10-99, 100-999, 1000-9999, etc. Every number in the i-th group has i digits. First we want to find the group which contains the number where does the digit...

Read

December 1, 2022

Single row keyboard

We will iterate over the word, find the index of the character in the keyboard and add the difference between the current and previous index to the result. Time complexity: O(n)...

Read

December 1, 2022

Path sum IV

We will convert the given array into a tree using Node objects. Afterwards, for each path from root to leaf, we can add the sum of that path to our answer. There are two steps, the tree...

Read

December 1, 2022

Factorial trailing zeroes

We will count the number of trailing zeroes in the factorial of the given number. We will count the number of 5s in the factorial of the given number. We will keep dividing the number by 5 and add...

Read
... 24 25 26 27 28 ...