1037. Valid Boomerang LeetCode Solution

In this guide, you will get 1037. Valid Boomerang LeetCode Solution with the best time and space complexity. The solution to Valid Boomerang problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Valid Boomerang solution in C++
  4. Valid Boomerang solution in Java
  5. Valid Boomerang solution in Python
  6. Additional Resources
1037. Valid Boomerang LeetCode Solution image

Problem Statement of Valid Boomerang

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

Complexity Analysis

  • Time Complexity: O(1)
  • Space Complexity: O(1)

1037. Valid Boomerang LeetCode Solution in C++

class Solution {
 public:
  bool isBoomerang(vector<vector<int>>& points) {
    return (points[1][0] - points[0][0]) * (points[2][1] - points[1][1]) !=
           (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]);
  }
};
/* code provided by PROGIEZ */

1037. Valid Boomerang LeetCode Solution in Java

class Solution {
  public boolean isBoomerang(int[][] points) {
    return                                                               //
        (points[1][0] - points[0][0]) * (points[2][1] - points[1][1]) != //
        (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]);
  }
}
// code provided by PROGIEZ

1037. Valid Boomerang LeetCode Solution in Python

class Solution:
  def isBoomerang(self, points: list[list[int]]) -> bool:
    return ((points[1][0] - points[0][0]) * (points[2][1] - points[1][1]) !=
            (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]))
# code by PROGIEZ

Additional Resources

See also  69. Sqrt(x) LeetCode Solution

Happy Coding! Keep following PROGIEZ for more updates and solutions.