Equal-Step Triplets
Imagine numbers on a number line: you need to find triples where each next value is exactly the same step away. Write a function arithmetic_triplets that receives a strictly increasing list nums and a number diff. A triplet of indices i < j < k counts if nums[j] - nums[i] == diff and nums[k] - nums[j] == diff. Return the number of such triplets.
Примеры
Ввод
[0, 1, 4, 6, 7, 10], 3Вывод
2Ввод
[4, 5, 6, 7, 8, 9], 2Вывод
2Ввод
[1, 2, 3], 1Вывод
1Нужно реализовать
def arithmetic_triplets(nums: list[int], diff: int) -> int:
Теги
arraysethashmap
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inVisible tests
1
Input
[0,1,4,6,7,10], 3Expected
22
Input
[4,5,6,7,8,9], 2Expected
23
Input
[1,2,3], 1Expected
14
Input
[1,2,3], 5Expected
05
Input
[0,3,6,9,12], 3Expected
36
Input
[10], 1Expected
0Focus radio
Paused · SomaFM · Fluid