Problem · Array

Count Skipped Numbers After Subtractions

EasyTiktokOA
See Tiktok hiring insights

You are given two positive integers x and y, and a sequence of positive integers numbers. Your task is to change x and y through this process: iterate through numbers from left to right, subtract each integer numbers[i] from the largest number among x and y (x in case of a tie), or skip numbers[i] if it is greater than both x and y.

Return the number of integers in numbers that will be skipped based on these criteria.

Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(numbers.length^2) will fit within the execution time limit.

Examples
01 · Example 1
x = 8
y = 12
numbers = [5, 6, 6, 3, 1, 1, 2]
return = 2
  • At the beginning, x = 8 and y = 12.
  • Since x < y currently, processing numbers[0] = 5 results in x = 8 and y = 7.
  • Since x > y now, processing numbers[1] = 6 results in x = 2 and y = 7.
  • Since x < y now, processing numbers[2] = 6 results in x = 2 and y = 1.
More Tiktok problems
drafts saved locally
public int solution(int x, int y, int[] numbers) {
  // write your code here
}
x8
y12
numbers[5, 6, 6, 3, 1, 1, 2]
expected2
checking account