Off-by-one on range boundaries
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Build confidence with an intuition-first walkthrough focused on array fundamentals.
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 == 3points[i].length == 20 <= xi, yi <= 100Problem summary: 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.
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: Array · Math
[[1,1],[2,3],[3,2]]
[[1,1],[2,2],[3,3]]
Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #1037: Valid Boomerang
class Solution {
public boolean isBoomerang(int[][] points) {
int x1 = points[0][0], y1 = points[0][1];
int x2 = points[1][0], y2 = points[1][1];
int x3 = points[2][0], y3 = points[2][1];
return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1);
}
}
// Accepted solution for LeetCode #1037: Valid Boomerang
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)
}
# Accepted solution for LeetCode #1037: Valid Boomerang
class Solution:
def isBoomerang(self, points: List[List[int]]) -> bool:
(x1, y1), (x2, y2), (x3, y3) = points
return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1)
// Accepted solution for LeetCode #1037: Valid Boomerang
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)
}
}
// Accepted solution for LeetCode #1037: Valid Boomerang
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);
}
Use this to step through a reusable interview workflow for this problem.
Two nested loops check every pair or subarray. The outer loop fixes a starting point, the inner loop extends or searches. For n elements this gives up to n²/2 operations. No extra space, but the quadratic time is prohibitive for large inputs.
Most array problems have an O(n²) brute force (nested loops) and an O(n) optimal (single pass with clever state tracking). The key is identifying what information to maintain as you scan: a running max, a prefix sum, a hash map of seen values, or two pointers.
Review these before coding to avoid predictable interview regressions.
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Wrong move: Temporary multiplications exceed integer bounds.
Usually fails on: Large inputs wrap around unexpectedly.
Fix: Use wider types, modular arithmetic, or rearranged operations.