#1037

Valid Boomerang

Easy
ArrayMathGeometryGeometrySet operations
LeetCode ↗

Approaches

Brute ForceOptimal
Complexity Comparison
Brute ForceOptimal Solution
Time
O(1)
O(1)
Space
O(1)
O(1)
💡

Intuition

Time O(1)Space O(1)

The optimal solution leverages the same area calculation but ensures that we check for distinct points in a single step, making the solution cleaner and more efficient.

⚙️

Algorithm

3 steps
  1. 1Step 1: Use a set to check if all three points are distinct.
  2. 2Step 2: Calculate the area using the same formula as before.
  3. 3Step 3: Return true if the area is greater than 0; otherwise, return false.
solution.py6 lines
1def isBoomerang(points):
2    if len(set(map(tuple, points))) != 3:
3        return False
4    return (points[0][0] * (points[1][1] - points[2][1]) +
5            points[1][0] * (points[2][1] - points[0][1]) +
6            points[2][0] * (points[0][1] - points[1][1])) != 0

Complexity note: The complexity remains constant since we are only working with three points.

  • 1Three points must be distinct to form a boomerang.
  • 2The area of the triangle formed by the points must be non-zero to ensure they are not collinear.

Solutions and explanations are original Tejav content. Problem titles © LeetCode — use the LeetCode button above for the full problem statement.