Valid Boomerang - Problem

Given an array points where points[i] = [x_i, y_i] represents a point on the X-Y plane, return true if these points form a boomerang.

A boomerang is a set of three points that are all distinct and not in a straight line.

Input & Output

Example 1 — Valid Boomerang
$ Input: points = [[1,1],[2,3],[3,2]]
Output: true
💡 Note: The three points are distinct and not collinear, so they form a valid boomerang. Cross product calculation: (2-1)×(2-1) - (3-1)×(3-1) = 1×1 - 2×2 = -3 ≠ 0
Example 2 — Collinear Points
$ Input: points = [[1,1],[2,2],[3,3]]
Output: false
💡 Note: All three points lie on the same straight line (y = x), so they cannot form a boomerang. Cross product: (2-1)×(3-1) - (2-1)×(3-1) = 1×2 - 1×2 = 0
Example 3 — Duplicate Points
$ Input: points = [[1,1],[2,3],[1,1]]
Output: false
💡 Note: Two points are identical ([1,1] appears twice), so they cannot form a valid boomerang. Cross product: (2-1)×(1-1) - (3-1)×(1-1) = 1×0 - 2×0 = 0

Constraints

  • points.length == 3
  • points[i].length == 2
  • 0 ≤ points[i][j] ≤ 50

Visualization

Tap to expand
Valid Boomerang INPUT X Y A (1,1) B (2,3) C (3,2) Input Array: [[1,1],[2,3],[3,2]] ALGORITHM STEPS 1 Extract Points A(1,1), B(2,3), C(3,2) 2 Calculate Vectors AB = (1,2), AC = (2,1) 3 Cross Product AB x AC = (1)(1)-(2)(2) (x2-x1)(y3-y1) - (y2-y1)(x3-x1) = (1)(1) - (2)(2) = 1 - 4 = -3 4 Check Result -3 != 0 --> Not collinear If cross product = 0, points are collinear (on same line) FINAL RESULT Boomerang Shape: A B C Points form an angle, NOT a straight line Output: true [OK] Valid Boomerang - All points distinct - Not collinear Key Insight: Three points form a boomerang if and only if they are NOT collinear. We use the cross product of vectors to check collinearity. If cross product equals zero, points lie on a straight line (not a boomerang). Formula: (x2-x1)*(y3-y1) - (y2-y1)*(x3-x1) != 0 means valid boomerang. Time: O(1), Space: O(1) TutorialsPoint - Valid Boomerang | Optimal Solution (Cross Product)
Asked in
Google 15 Amazon 12 Microsoft 8
23.5K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen