Ctrl K

Evenly Spaced Triples

Easy
You are given a strictly increasing array values and a positive integer step. A triple of indices i < j < k is good if values[j] - values[i] == step and values[k] - values[j] == step. Return the number of good triples.
Example 1
values=[2, 5, 8, 9, 11, 14], step=3 → 3

The triples 2, 5, 8 / 5, 8, 11 / 8, 11, 14 all work.

Example 2
values=[0, 1, 3, 4, 7], step=2 → 0

Each step must be 2: 1 → 3 exists but 5 does not, and 0 → 2 fails since there is no 2. The answer is 0.

Example 3
values=[10, 20, 30, 40], step=10 → 2
Constraints
  • 3 ≤ len(values) ≤ 200
  • 0 ≤ values[i] ≤ 200
  • 1 ≤ step ≤ 50
  • values is strictly increasing
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsOriginal Array From Two Shifts HardValues in Both Lists EasyShared Values With Repeats EasyTwice as Much EasyThree Addends and a Later Total Easy
loading Python…
Input
values=[2, 5, 8, 9, 11, 14], step=3
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.