Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopsorting · two-pointers · pair-counting
The organizer’s problem statement is available at the official source link.
difference threshold
Count pairs outside a value band
A pair qualifies when the sorted values differ by at least K, on either side.
sorted x_i <= x_jdifference = x_j - x_iqualifies when difference >= K
- 1
Sort values
Sort the sequence. - 2
Find threshold boundary
For each smaller endpoint, locate the first value at least K larger. - 3
Count qualifying pairs
Count all values from that boundary to the end and avoid counting each pair twice.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.