Valid Boomerang - Problem
Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, determine if these three points form a valid boomerang.
A boomerang is a set of three points that are:
- All distinct (no two points are the same)
- Not collinear (not in a straight line)
Think of it as checking if three points can form a triangle - if they're all on the same line, you can't make a triangle (or a boomerang shape)!
Goal: Return true if the three points form a valid boomerang, false otherwise.
Example: Points [[1,1], [2,3], [3,2]] form a boomerang because they create a triangle, while [[1,1], [2,2], [3,3]] don't because they're all on the same diagonal line.
Input & Output
example_1.py โ Basic Valid Boomerang
$
Input:
[[1,1],[2,3],[3,2]]
โบ
Output:
true
๐ก Note:
These three points form a triangle (not collinear), so they make a valid boomerang. The cross product calculation: (2-1)*(2-1) - (3-1)*(3-1) = 1*1 - 2*2 = -3 โ 0
example_2.py โ Collinear Points
$
Input:
[[1,1],[2,2],[3,3]]
โบ
Output:
false
๐ก Note:
All three points lie on the same diagonal line y=x, so they cannot form a boomerang. The cross product: (2-1)*(3-1) - (2-1)*(3-1) = 1*2 - 1*2 = 0
example_3.py โ Duplicate Points
$
Input:
[[1,1],[2,2],[1,1]]
โบ
Output:
false
๐ก Note:
The first and third points are identical, so we don't have three distinct points. The cross product: (2-1)*(1-1) - (2-1)*(1-1) = 1*0 - 1*0 = 0
Constraints
- points.length == 3
- points[i].length == 2
- -100 โค xi, yi โค 100
- The input will always contain exactly three points
Visualization
Tap to expand
Understanding the Visualization
1
Position the Posts
Place three fence posts at the given coordinates
2
Form Vectors
Create directional arrows from the first post to the other two
3
Calculate Cross Product
Use the cross product formula to measure the 'turning angle'
4
Check Result
If cross product is zero, posts are aligned (straight fence). If non-zero, they form a triangle (valid boomerang)!
Key Takeaway
๐ฏ Key Insight: The cross product method elegantly determines collinearity without division, making it the most robust solution for checking if three points can form a boomerang!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code