Talentd
FleetCode
Make and follow sheets.Sign in

Valid Boomerang solution and explanation

EasyArrayGeometryMath5 min read40.5% acceptanceUpdated 9 Apr 2026
1037. Valid Boomerang | Interview Preparation | Tamil | code iocode io - Tamil · 9:30 · 2K viewsWatch on YouTube
9 more videos on this problem
  1. 1037. Valid Boomerang | Interview Preparation | Tamil | code iocode io - Tamil · 9:30 · 2K views
  2. 1037. Valid Boomerang || leetcode || easy question || c++ solution with explanationcode Explainer · 5:06 · 872 views
  3. Valid Boomerang | LeetCode | JAVA | beats 100 % time and spaceKnowledge Amplifier · 9:43 · 797 views
  4. Vol84 - Leetcode - Problem 1037 - Valid boomerang - Golang - Phỏng vấn - Thuật toánYuh lập trình viên · 11:32 · 748 views
  5. 1037. Valid Boomerang | Interview Preparation | English | code iocode io - English · 9:47 · 740 views
  6. 1037. Valid Boomerang (Leetcode Easy)Programming Live with Larry · 4:34 · 480 views
  7. LeetCode 1037 | Valid Boomerang | Math | JavaSleepy Cracker · 5:19 · 365 views
  8. Leetcode 1037 Valid BoomerangMath Geeks · 2:15 · 272 views
  9. Valid Boomerang | LeetCode | Problem 1037Elite Code · 29:21 · 235 views
  10. leetCode 1037 in JavaScript - Valid Boomerang | JSer - algorithm & JavaScriptJSer · 4:14 · 201 views

The problem

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

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

Example 1:

Input: points = [[1,1],[2,3],[3,2]]
Output: true

Example 2:

Input: points = [[1,1],[2,2],[3,3]]
Output: false

Constraints:

  • points.length == 3
  • points[i].length == 2
  • 0 <= xi, yi <= 100

Approach overview

Problem Overview: You are given three points on a 2D plane. A boomerang is valid only if the points are all distinct and they do not lie on the same straight line. The task is to determine whether these three coordinates form a non‑collinear triangle.

The core observation: three points form a straight line if their slopes match or if the area of the triangle formed by them equals zero. Both approaches rely on basic geometry and simple math operations on coordinates stored in an array.

Approach 1: Using Slope to Determine Collinearity (Time: O(1), Space: O(1))

Two line segments share the same slope when three points are collinear. Compute the slope between point A→B and A→C and compare them. Instead of dividing (which risks floating‑point errors or division by zero), use cross multiplication: (y2 - y1) * (x3 - x1) == (y3 - y1) * (x2 - x1). If this equality holds, the slopes are identical and the points lie on the same line. Otherwise, they form a valid boomerang.

This method relies purely on integer arithmetic, which avoids precision problems and keeps the implementation clean. Since the input always contains exactly three points, you perform only a constant number of operations. That makes the runtime O(1) and space O(1). This is usually the most straightforward way to solve the problem.

Approach 2: Using Area of Triangle Formed by Points for Collinearity (Time: O(1), Space: O(1))

Three points are collinear when the triangle they form has zero area. Using the determinant formula for the area of a triangle with coordinates:

Area = x1(y2 - y3) + x2(y3 - y1) + x3(y1 - y2)

If the computed value equals zero, the points lie on a straight line and the boomerang is invalid. Any non‑zero value means the points form a triangle, which satisfies the boomerang condition. This technique is mathematically equivalent to the slope method but framed through geometric area.

The computation uses only a few arithmetic operations and no additional memory, giving the same O(1) time and O(1) space complexity. Some engineers prefer this approach because the determinant formula is widely used in computational geometry.

Recommended for interviews: The slope comparison using cross multiplication is typically expected. It directly expresses the definition of collinearity and avoids floating‑point division. The triangle area formula demonstrates deeper geometry intuition, but both solutions run in constant time. Showing either approach signals strong fundamentals with coordinate geometry and basic mathematical reasoning.

Approach 1: Using Slope to Determine Collinearity

To determine if the three points form a boomerang, we first check if any two points are the same, which would immediately disqualify them as a boomerang since all points must be distinct. Then, we check that the slope between any two pairs of points is different, which ensures they are not collinear. If the slopes between (points[0], points[1]) and (points[0], points[2]) are different, the points are not on a straight line and hence form a boomerang.

class Solution:
    def isBoomerang(self, points: List[List[int]]) -> bool:
        return (points[0][0] != points[1][0] or points[0][1] != points[1][1]) and \
               (points[0][0] != points[2][0] or points[0][1] != points[2][1]) and \
               (points[1][0] != points[2][0] or points[1][1] != points[2][1]) and \
               (points[0][1] - points[1][1]) * (points[0][0] - points[2][0]) != \
               (points[0][1] - points[2][1]) * (points[0][0] - points[1][0])
class Solution {
    public boolean isBoomerang(int[][] points) {
        return (points[0][0] != points[1][0] || points[0][1] != points[1][1]) &&
               (points[0][0] != points[2][0] || points[0][1] != points[2][1]) &&
               (points[1][0] != points[2][0] || points[1][1] != points[2][1]) &&
               (points[0][1] - points[1][1]) * (points[0][0] - points[2][0]) !=
               (points[0][1] - points[2][1]) * (points[0][0] - points[1][0]);
    }
}
#include <vector>
#include <utility>
using namespace std;

bool isBoomerang(vector<vector<int>>& points) {
    return (points[0][0] != points[1][0] || points[0][1] != points[1][1]) &&
           (points[0][0] != points[2][0] || points[0][1] != points[2][1]) &&
           (points[1][0] != points[2][0] || points[1][1] != points[2][1]) &&
           (points[0][1] - points[1][1]) * (points[0][0] - points[2][0]) !=
           (points[0][1] - points[2][1]) * (points[0][0] - points[1][0]);
}
var isBoomerang = function(points) {
    return (points[0][0] !== points[1][0] || points[0][1] !== points[1][1]) &&
           (points[0][0] !== points[2][0] || points[0][1] !== points[2][1]) &&
           (points[1][0] !== points[2][0] || points[1][1] !== points[2][1]) &&
           (points[0][1] - points[1][1]) * (points[0][0] - points[2][0]) !==
           (points[0][1] - points[2][1]) * (points[0][0] - points[1][0]);
};
#include <stdbool.h>

bool isBoomerang(int points[3][2]) {
    return (points[0][0] != points[1][0] || points[0][1] != points[1][1]) &&
           (points[0][0] != points[2][0] || points[0][1] != points[2][1]) &&
           (points[1][0] != points[2][0] || points[1][1] != points[2][1]) &&
           (points[0][1] - points[1][1]) * (points[0][0] - points[2][0]) !=
           (points[0][1] - points[2][1]) * (points[0][0] - points[1][0]);
}
public class Solution {
    public bool IsBoomerang(int[][] points) {
        return (points[0][0] != points[1][0] || points[0][1] != points[1][1]) &&
               (points[0][0] != points[2][0] || points[0][1] != points[2][1]) &&
               (points[1][0] != points[2][0] || points[1][1] != points[2][1]) &&
               (points[0][1] - points[1][1]) * (points[0][0] - points[2][0]) !=
               (points[0][1] - points[2][1]) * (points[0][0] - points[1][0]);
    }
}

The Python implementation uses list comparisons to check that all points are distinct and compares slopes using cross multiplication to check for non-collinearity.

Complexity

Time Complexity: O(1) because each operation takes constant time.
Space Complexity: O(1) since no additional space outside of input is used.

Try this approach in the editor

Approach 2: Using Area of Triangle Formed by Points for Collinearity

The area of a triangle can be used to determine collinearity of three points. If the area is zero, the points are collinear. The formula for the area of the triangle formed by points A(x1,y1), B(x2,y2), and C(x3,y3) is 0.5 * |x1(y2-y3) + x2(y3-y1) + x3(y1-y2)|. If the area derived from this formula is zero, the points are on a straight line. If the area is non-zero, the points form a triangle, suggesting a valid boomerang.

class Solution:
    def isBoomerang(self, points: List[List[int]]) -> bool:
        area = points[0][0] * (points[1][1] - points[2][1]) + \
               points[1][0] * (points[2][1] - points[0][1]) + \
               points[2][0] * (points[0][1] - points[1][1])
        return area != 0
class Solution {
    public boolean isBoomerang(int[][] points) {
        int area = points[0][0] * (points[1][1] - points[2][1]) +
                   points[1][0] * (points[2][1] - points[0][1]) +
                   points[2][0] * (points[0][1] - points[1][1]);
        return area != 0;
    }
}
#include <vector>
#include <cmath>
using namespace std;

bool isBoomerang(vector<vector<int>>& points) {
    int area = points[0][0]*(points[1][1] - points[2][1]) +
               points[1][0]*(points[2][1] - points[0][1]) +
               points[2][0]*(points[0][1] - points[1][1]);
    return area != 0;
}
var isBoomerang = function(points) {
    let area = points[0][0] * (points[1][1] - points[2][1]) +
               points[1][0] * (points[2][1] - points[0][1]) +
               points[2][0] * (points[0][1] - points[1][1]);
    return area !== 0;
};
#include <stdbool.h>

bool isBoomerang(int points[3][2]) {
    int area = points[0][0]*(points[1][1] - points[2][1]) +
               points[1][0]*(points[2][1] - points[0][1]) +
               points[2][0]*(points[0][1] - points[1][1]);
    return area != 0;
}
public class Solution {
    public bool IsBoomerang(int[][] points) {
        int area = points[0][0] * (points[1][1] - points[2][1]) +
                   points[1][0] * (points[2][1] - points[0][1]) +
                   points[2][0] * (points[0][1] - points[1][1]);
        return area != 0;
    }
}

In Python, the code checks if the geometric area of the triangle defined by the three points is non-zero, which implies the points are not aligned.

Complexity

Time Complexity: O(1) because each operation takes constant time.
Space Complexity: O(1) since no additional space outside of input is used.

Try this approach in the editor

Approach 3: Slope Comparison

Let the three points be (x_1, y_1), (x_2, y_2), and (x_3, y_3). The formula for calculating the slope between two points is \frac{y_2 - y_1}{x_2 - x_1}.

To ensure that the three points are not collinear, the condition \frac{y_2 - y_1}{x_2 - x_1} neq \frac{y_3 - y_2}{x_3 - x_2} must be satisfied. By transforming the equation, we get (y_2 - y_1) cdot (x_3 - x_2) neq (y_3 - y_2) cdot (x_2 - x_1).

Note:

  1. When the slope between two points does not exist, i.e., x_1 = x_2, the transformed equation still holds.
  2. If there are precision issues with division in slope comparison, it can be converted to multiplication.

Time complexity is O(1).

function isBoomerang(points: number[][]): boolean {
    const [x1, y1] = points[0];
    const [x2, y2] = points[1];
    const [x3, y3] = points[2];
    return (x1 - x2) * (y2 - y3) !== (x2 - x3) * (y1 - y2);
}
func isBoomerang(points [][]int) bool {
	x1, y1 := points[0][0], points[0][1]
	x2, y2 := points[1][0], points[1][1]
	x3, y3 := points[2][0], points[2][1]
	return (y2-y1)*(x3-x2) != (y3-y2)*(x2-x1)
}
impl Solution {
    pub fn is_boomerang(points: Vec<Vec<i32>>) -> bool {
        let (x1, y1) = (points[0][0], points[0][1]);
        let (x2, y2) = (points[1][0], points[1][1]);
        let (x3, y3) = (points[2][0], points[2][1]);
        (x1 - x2) * (y2 - y3) != (x2 - x3) * (y1 - y2)
    }
}
Try this approach in the editor

Complexity comparison

ApproachComplexity
Using Slope to Determine Collinearity

Time Complexity: O(1) because each operation takes constant time.
Space Complexity: O(1) since no additional space outside of input is used.

Using Area of Triangle Formed by Points for Collinearity

Time Complexity: O(1) because each operation takes constant time.
Space Complexity: O(1) since no additional space outside of input is used.

Slope Comparison–

Complexity analysis

ApproachTimeSpaceWhen to Use
Slope Comparison (Cross Multiplication)O(1)O(1)General case; simplest implementation without floating point division
Triangle Area / Determinant MethodO(1)O(1)When applying computational geometry formulas or determinant logic

Frequently asked questions

Is Valid Boomerang easy or hard?

Valid Boomerang is classified as an Easy problem on LeetCode. The task requires recognizing that three points are collinear when their slopes match or the triangle area is zero. Once that observation is made, the implementation is straightforward.

Valid Boomerang Python/Java solution

In Python or Java, compute the cross multiplication condition: (y2 - y1) * (x3 - x1) != (y3 - y1) * (x2 - x1). If the expression is true, the points form a valid boomerang. The implementation is only a few lines and runs in constant time.

How to solve Valid Boomerang in O(n)?

An O(n) solution is unnecessary because the problem always has three points. The optimal approach directly compares slopes or computes the triangle area using constant arithmetic operations. Both methods achieve O(1) time and O(1) space complexity.

What is the best approach for Valid Boomerang?

The slope comparison approach using cross multiplication is the most common solution. It checks whether (y2 − y1) * (x3 − x1) equals (y3 − y1) * (x2 − x1). If the values differ, the points are not collinear and form a valid boomerang. The method runs in O(1) time and O(1) space.

Is Valid Boomerang asked at Google/Amazon/Meta?

Valid Boomerang represents a basic geometry and math reasoning problem sometimes used in screening rounds or coding practice sets. Similar collinearity or coordinate geometry questions appear in interviews at companies like Google, Amazon, and Meta, especially for entry‑level roles.

What data structure is used in Valid Boomerang?

The input is typically stored in a small array containing three coordinate pairs. The solution mainly relies on arithmetic operations and geometric reasoning rather than complex data structures.

What is the time complexity of Valid Boomerang?

Valid Boomerang runs in O(1) time because the input always contains exactly three points. The algorithm performs only a few arithmetic operations to compare slopes or compute triangle area. Space complexity is also O(1) since no additional data structures are required.

Comments

Now write it yourselfClose this page and solve Valid Boomerang in the editor, without looking.
Practise Valid Boomerang