Given a positive integer num consisting only of digits 6 and 9.
Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).
Input: num = 9669
Changing the first digit results in 6669.
Changing the second digit results in 9969.
Changing the third digit results in 9699.
Changing the fourth digit results in 9666.
The maximum number is 9969.
Input: num = 9996
Explanation: Changing the last digit 6 to 9 results in the maximum number.
Input: num = 9999
Explanation: It is better not to apply any change.
1 <= num <= 10^4
num‘s digits are 6 or 9.
Replace the highest 6 to 9, if no 6, return the original number.
There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e The length of the garden is n).
There are n + 1 taps located at points [0, 1, ..., n] in the garden.
Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th tap can water the area [i - ranges[i], i + ranges[i]] if it was open.
Return the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1.
Input: n = 5, ranges = [3,4,1,1,0,0]
Explanation: The tap at point 0 can cover the interval [-3,3]
The tap at point 1 can cover the interval [-3,5]
The tap at point 2 can cover the interval [1,3]
The tap at point 3 can cover the interval [2,4]
The tap at point 4 can cover the interval [4,4]
The tap at point 5 can cover the interval [5,5]
Opening Only the second tap will water the whole garden [0,5]
Input: n = 3, ranges = [0,0,0,0]
Explanation: Even if you activate all the four taps you cannot water the whole garden.
Input: n = 7, ranges = [1,2,1,0,2,1,0,1]
Input: n = 8, ranges = [4,0,0,0,0,0,0,0,4]
Input: n = 8, ranges = [4,0,0,0,4,0,0,0,4]
There are n people whose IDs go from 0 to n - 1 and each person belongs exactly to one group. Given the array groupSizes of length n telling the group size each person belongs to, return the groups there are and the people’s IDs each group includes.
You can return any solution in any order and the same applies for IDs. Also, it is guaranteed that there exists at least one solution.
Input: groupSizes = [3,3,3,3,3,1,3]
Other possible solutions are [[2,1,6],,[0,4,3]] and [,[0,6,2],[4,3,1]].
On a plane there are n points with integer coordinates points[i] = [xi, yi]. Your task is to find the minimum time in seconds to visit all points.
You can move according to the next rules:
In one second always you can either move vertically, horizontally by one unit or diagonally (it means to move one unit vertically and one unit horizontally in one second).
You have to visit the points in the same order as they appear in the array.
Input: points = [[1,1],[3,4],[-1,0]]
Explanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]
Time from [1,1] to [3,4] = 3 seconds
Time from [3,4] to [-1,0] = 4 seconds
Total time = 7 seconds
Input: points = [[3,2],[-2,2]]
points.length == n
1 <= n <= 100
points[i].length == 2
-1000 <= points[i], points[i] <= 1000
Solution: Geometry + Greedy
dx = abs(x1 – x2) dy = abs(y1 – y2)
go diagonally first for min(dx, dy) steps, and then go straight line for abs(dx – dy) steps.