这一类题目,题目都是直接要求你return 某个x,一般用定于 THE x number, return的requirment 就是1纬的。
1608. Special Array With X Elements Greater Than or Equal X (Easy)
# directly guess x and count the nums >= x
"Return x if the array is ...."
1802. Maximum Value at a Given Index in a Bounded Array (Medium)
# directly guess the value of the maximum index (not the index!)
# calculate the sum and see if it meets the maxsum requirement
# twist: arithmetic sequence sum
"Return nums[index] of the constructed array..."
875. Koko Eating Bananas (Medium)
# directly guess a speed
# count hours that need to finish all banans
"Return the minimum integer k such that she can eat all the bananas within h hours."
1231. Divide Chocolate (Hard)
# directly guess the minimum of maximized sweetness
# count how many K we can divide
"Find the maximum total sweetness of the piece you can get ..."
410. Split Array Largest Sum (Hard)
# directly guess the minimum largest sum
# count how many subarrays there are
"Write an algorithm to minimize the largest sum among these m subarrays."
719. Find K-th Smallest Pair Distance (Hard)
# directly guess dist m
# count /check Kth pairs have dist <= m
"return the kth smallest distance among all the pairs"
直接猜答案的变形 1
378. Kth Smallest Element in a Sorted Matrix (Medium)
# directly guess the possible value of the Kth smallest element
# check if it is the Kth element
"return the kth smallest element in the matrix."
1102. Path With Maximum Minimum Value (Medium)
# directly guess the minimum value of the maximized path
# check if a path exists
"find the maximum score of a path starting at ..."
1631. Path With Minimum Effort (Medium)
# directly guess the minimum effort
# check if there's such a path
"Return the minimum effort required..."
直接猜答案的变形 2
774. Minimize Max Distance to Gas Station (Hard)
# twist: assuming the distance between stations are [d1, d2, d3...] 变形在这里
# directly guess the smallest cut off distance
# count how many d values meet the category
# twist: return a real number
"Return the smallest possible value..."
以上的题目都是直接 return binary search 搜出来的值。
直接猜答案的变形 3
1300. Sum of Mutated Array Closest to Target (Medium)
# (directly) guess the possible sum
# then calculate the (closest) sum
# twist: need to compare the left vs. left - 1
# because the final value can be larger or smaller, we need abs diff
type 1: 用binary search return 出来的数,再稍微做一下简单的算数,便是答案
1648. Sell Diminishing-Valued Colored Balls (Medium)
# guess the cutoff price - variant of 410
# then count how many orders with such cut off price
# return the total value of those orders
"Return the maximum total value that you can attain after selling orders colored balls."
4. Median of Two Sorted Arrays (Hard)
# Twist: guess the cut off index(length) of arr 1 vs. arr 2
# then calculate the median
274/275. H-Index (Medium)
# guess the cutoff index/position of -------> 在它右边的每个值都 >= 右边的长度 ie. n-index
# check if this index fits the h-index definition
# then return the length of the right side
"""
# 1608
a number x such that there are exactly x numbers in nums that are greater than or equal to x. Notice that x does not have to be an element in nums.
# 274
return compute the researcher's h-index.
an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each.
"""
658. Find K Closest Elements (Medium)
# guess the left boundary - 所有符合条件的数中,左边第一个
# check if (target - left boundary) < left boundary + k - target
# return left boundary + k
"return the k closest integers to x in the array...."
type 3: 用binary search猜数量,然后猜出来的数量 + 题目要求的k,就是我们要的数。
感觉这种就是专门针对这种missing numbers的题目。
1539. Kth Missing Positive Number (Easy)
# given that we can have k missing numbers, guess the numbers of not missing number before having k missing numbers
# binary search returns - the length of not missing numbers
# missing = nums[mid] - nums[0] - mid (mid 代表的就是 没有miss数字的数量)
# return not missing number + k + starting value = Kth missing number
1060. Missing Element in Sorted Array (Medium)
# given that we can have k missing numbers, guess the numbers of not missing number before having k missing numbers
# binary search returns - the length of not missing numbers
# return not missing number + k + starting value = Kth missing number