Skip to content

1534. Count Good Triplets #1558

Answered by mah-shamim
mah-shamim asked this question in Q&A
Apr 14, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We need to count the number of good triplets in an array. A triplet is considered good if it meets specific conditions involving absolute differences between elements at different indices.

Approach

  1. Brute Force Enumeration: Given the constraints (array length up to 100), a brute force approach is feasible. We will check all possible triplets (i, j, k) where 0 <= i < j < k < arr.length.
  2. Conditions Check: For each triplet, we check the following conditions:
    • The absolute difference between elements at indices i and j must be <= a.
    • The absolute difference between elements at indices j and k must be <= b.
    • The absolute difference between elements at indices i and k must be <= c.
  3. Optimization:…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Apr 14, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Apr 14, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants