Skip to content

Practice Count Good Triplets

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1534
LeetCode Problem

Count Good Triplets

Problem Statement

Count triples of indices i < j < k in arr satisfying all three bounds: |arr[i] - arr[j]| <= a, |arr[j] - arr[k]| <= b and |arr[i] - arr[k]| <= c. The vertical bars denote absolute value.

Source: Count Good Triplets on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3
Output
4

# Example 2

Input
arr = [1,1,2,2,3], a = 0, b = 0, c = 1
Output
0

Constraints

3 <= arr.length <= 100
0 <= arr[i] <= 1000
0 <= a, b, c <= 1000

Related LeetCode Problems

Practice more problems similar to Count Good Triplets.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.