bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 2367. Number of Arithmetic Triplets

2367. Number of Arithmetic Triplets

Leetcode Solutions

Check [n - diff] and [n - * diff]

  1. Initialize a boolean array seen of size 201 (since 0 <= nums[i] <= 200) to keep track of which numbers have been seen in the input array.
  2. Initialize a result counter res to 0.
  3. Iterate over each number n in the input array nums.
  4. If n is greater than or equal to 2 * diff, check if seen[n - diff] and seen[n - 2 * diff] are both true.
  5. If both are true, increment res by 1.
  6. Mark seen[n] as true.
  7. After the loop, return the result counter res.
UML Thumbnail

Brute Force Triple Nested Loop

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...