Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopsubsequences · dynamic-programming · counting
The organizer’s problem statement is available at the official source link.
subsequence dag
Keep each adjacent value jump within K
A subsequence is good when each chosen value differs from the previous chosen value by at most K. Count index subsequences, including distinct choices with equal values.
- 1
Create position nodes
Treat array positions as separate nodes, including equal-valued positions. - 2
Connect valid jumps
Connect compatible later positions when their value gap is at most K. - 3
Count index paths
Count nonempty paths ending at every node.
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.