Back to questions

Arithmetic Triplets Oracle Python Interview Question

Arithmetic Triplets

Oracle Python Interview Question

You are given a strictly increasing array of integers , and a positive integer . An arithmetic triplet with a gap of is defined as triplet of integers from where:

  • Each value is unique, and the triplet is in increasing order:
  • The difference in the values from and are both exactly the specified value

Return the number of arithmetic triplets with a gap of that exist in .

Example #1

Input: nums = [1, 2, 4, 6, 7, 11, 12] ; diff = 5

Output: 2

Explanation: For a diff of 5, there are two valid triplets: (1,6,11) and (2,7,12)

Input

Python

Output