Problems


December 6, 2022

Describe the painting

We will loop over the segments and add the start and end points to a list. Then we will sort the list and loop over it. We will keep track of the current color and the current start point. When we...

Read

December 6, 2022

Encode and decode strings

We will use a delimiter to separate the strings. Then we will loop over the strings and add the length of the string and the delimiter to the result. Finally, we will add the string to the result....

Read

December 5, 2022

Find center of star graph

As it's a start graph, each edge will be connected to the center. So we can just check the first 2 edges and return the node that is connected to both of them. Time complexity: O(1)...

Read

December 5, 2022

One edit distance

We will check if the length of the strings are equal or not. If they are equal, we will check if there is only one character that is different. If they are not equal, we will check if the length...

Read

December 5, 2022

Remove interval

We will iterate over each interval, if the interval doesn't overlap with the to be removed interval, we just add it to the output. If start is less than remove start, we take the remove start as end....

Read

December 5, 2022

Fraction to recurring decimal

We will use a dictionary to store the remainder and the index of the remainder. If the remainder is already in the dictionary, we will add the parenthesis and return the result. Time complexity:...

Read

December 5, 2022

Find k pairs with smallest sums

We will use a min heap to store the smallest sum. We will add the first element of each array to the heap. Then we will pop the smallest element from the heap and add the next element of the array...

Read

December 5, 2022

Middle of the linked list

We will take two pointers, one will move one step at a time and the other will move two steps at a time. When the second pointer reaches the end of the list, the first pointer will be at the middle...

Read

December 5, 2022

Wiggle sort

We will loop over the array, that 2 elements per iteration, then sort 2 elements once ascending and then descending order and swap them. We will do this until we reach the end of the array. Time...

Read

December 5, 2022

Minimum score of a path between two cities

We will create an adjacency list for the graph. Then we traverse the graph with BFS and keep track of the minimum score for each node. We will return the minimum score for the destination node....

Read
... 22 23 24 25 26 ...