### Valid Boomerang LeetCode Solution - The Coding Shala

Home >> LeetCode >> Valid Boomerang

In this post, we will learn how to solve LeetCode's Valid Boomerang problem and will implement its solution in Java.

## Valid Boomerang Problem

A boomerang is a set of 3 points that are all distinct and not in a straight line. Given a list of three points in the plane, return whether these points are a boomerang.

Example 1:
Input: [[1,1],[2,3],[3,2]]
Output: true

Example 2:
Input: [[1,1],[2,2],[3,3]]
Output: false

## Valid Boomerang Java Solution

Approach 1

We can find the slope of the first two points and the last two points if it's the same then it will be a straight line.

Solpe is (y2-y1)/(x2-x1) == (y3-y2)/(x3-x2)  or in other words (y2-y1)*(x3-x2) == (y3-y2)*(x2-x1).

We can also find the area of the triangle that is made by these three points. The area will be zero of the straight line.

Java Program:

```class Solution {
public boolean isBoomerang(int[][] points) {
//find slope, if same then straight line
// (y2-y1)/(x2-x1) == (y3-y2)/(x3-x2)
//or (y2-y1)*(x3-x2) == (y3-y2)*(x2-x1)

int x1 = points;
int y1 = points;
int x2 = points;
int y2 = points;
int x3 = points;
int y3 = points;

if((y2-y1)*(x3-x2) == (y3-y2)*(x2-x1)) return false;

return true;
}
}
```

Other Posts You May Like