Problems


January 9, 2023

Confusing number

We will use a dictionary to map the digits to their confusing digits. We will iterate through the digits of the number and check if the confusing digit is the same as the original digit. If it is, we...

Read

January 8, 2023

Find xor beauty of array

First, note that by symmetry of i and j, we know that the value of ((nums[i] | nums[j]) & nums[k]) and ((nums[j] | nums[i]) & nums[k]) are equal. Which then implies that for a pair of (i, j)...

Read

January 8, 2023

Minimum health to beat game

Without considering the armor, we need 1 + total_damage amount of health to pass. Considering the armor, we just use it to shield the most severe damage, call it max_damage, and it should save us...

Read

January 8, 2023

Max points on a line

We will calculate the slope of each pair of points. If the slope is the same, we will increase the count. If the slope is different, we will update the maximum count. Time complexity:...

Read

January 7, 2023

Assign cookies

We will sort both child and cookies. Then we will try to satisfy the child with the smallest greed factor. If the cookie is not enough, we will move to the next cookie. If the cookie is enough, we...

Read

January 6, 2023

Minimum operations to make the array alternating

We count all the elements of odd and even positions separately and take most common 2 numbers from each group. If there is no common number, we will take the most common number from each group. Then...

Read

January 6, 2023

Most profit assigning work

We will zip together difficulty and profit as jobs and sort them by difficulty. Then we will sort workers. For each worker, we will find the maximum profit he can make under his ability. The maximum...

Read

January 6, 2023

Maximum ice cream bars

We will sort the input costs array, then iterate the array, if the current cost is less than coins, we will update coins to be coins-costs[i], and...

Read

January 6, 2023

Max increase to keep city skyline

For grid[i][j], it can't be higher than the maximun of its row nor the maximum of its column. So the maximum increasing height for a building at (i, j) is min(row[i], col[j]) -...

Read

January 5, 2023

Steps to make array non decreasing

Iterating the input A backward, then for each nums[i], find how many round it can eat on its right. dp[i] means the number of element nums[i] can eat on its...

Read