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 = 8andy = 12. - Since
x < ycurrently, processingnumbers[0] = 5results inx = 8andy = 7. - Since
x > ynow, processingnumbers[1] = 6results inx = 2andy = 7. - Since
x < ynow, processingnumbers[2] = 6results inx = 2andy = 1.
More Tiktok problems
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026
- Check Even-Position MonotonicityOA · Seen Jun 2026
- Count Alternating Tile GroupsOA · Seen Jun 2026
- Count Even-Digit NumbersOA · Seen Jun 2026
- Inventory Discount TrackerOA · Seen Jun 2026
- Construct WDL StringOA · Seen Jun 2026
- Find Sum PairsOA · Seen Jun 2026
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