Problems


October 18, 2022

Reduction operations to make the array elements equal

We will sort the array in descending order, then iterate over the array and count the number of elements that are less than the current element. Finally return the sum of the counts. Time...

Read

October 17, 2022

Best sightseeing pair

Count the current best score in all previous sightseeing spot. Note that, as we go further, the score of previous spot decrement. cur will record the best score that we have met. We iterate each...

Read

October 16, 2022

Find numbers with even number of digits

Given an array nums of integers, return how many of them contain an even number of digits. We will use a helper function to count the number of digits of each number. Then iterate over...

Read

October 16, 2022

Delete leaves with a given value

We will use recursion to solve this problem. If the current node is a leaf and its value is the target value, we will return None. Otherwise, we will recursively call the function on the...

Read

October 16, 2022

Minimum difficulty of a job schedule

We will apply DFS to find the the minimum difficulty if start work at ith job with d days left. If d = 1, only one day left, we have to do all jobs, return the maximum difficulty of...

Read

October 16, 2022

Convert binary number in a linked list to integer

We will use a variable res to store the result. We will iterate over the linked list, and for each node, we will shift res to the left by 1 bit, and add the value of the...

Read

October 15, 2022

String compression II

Start from the beginning of the s, you would meet two situations: The next character is the same as the last one, e.g. "aaa" with the next one still "a". The former characters would be "a3", so you...

Read

October 14, 2022

Delete the middle node of a linked list

We will take a two pointer approach to find the middle node, and then we will delete the middle node. The first pointer will move one step at a time, and the second pointer will move two steps at a...

Read

October 13, 2022

Find missing observations

We are given an array of n integers. We are also given m missing values. We need to find all the possible values that can be assigned to the missing values such that the...

Read

October 13, 2022

Shift 2d grid

We are given a 2d grid of size m x n and an integer k. We need to shift the grid k times. In one shift operation, we shift the grid by one cell to the right....

Read
... 48 49 50 51 52 ...