Solution


Approach 1: Brute Force

Intuition

If , the sum can't be less than or equal to the bound. Similarly for .

Thus, we only have to check for .

We can use a HashSet to store all the different values.

Complexity Analysis

  • Time Complexity: .

  • Space Complexity: .


Analysis written by: @awice.