question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
valid-boomerang | [Python 3] Triangle Area | python-3-triangle-area-by-hari19041-f8rr | Concept: We need to check if the 3 points are in a straight line or not.\nMath: We can find the area of the triangle formed by the three points and check if the | hari19041 | NORMAL | 2022-04-27T06:26:51.161700+00:00 | 2022-04-27T06:26:51.161744+00:00 | 3,143 | false | **Concept:** We need to check if the 3 points are in a straight line or not.\nMath: We can find the area of the triangle formed by the three points and check if the area is non-zero.\n**DO UPVOTE IF YOU FOUND IT HELPFUL.**\n\n\n```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n x1, y1 = points[0]\n x2, y2 = points[1]\n x3, y3 = points[2]\n \n area = abs(x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2))/2\n return area != 0\n``` | 27 | 0 | ['Math', 'Python', 'Python3'] | 1 |
valid-boomerang | C++ Calculate Slopes!! (1 liner with explanation) | c-calculate-slopes-1-liner-with-explanat-zgvt | \tclass Solution {\n\tpublic:\n\t\tbool isBoomerang(vector>& points) {\n\t\t\tif(points.size() != 3)\n\t\t\t\treturn false;\n\n\t\t\t// formula for slope = (y2 | ddev | NORMAL | 2019-05-05T04:01:22.343792+00:00 | 2019-05-05T04:17:32.758644+00:00 | 2,325 | false | \tclass Solution {\n\tpublic:\n\t\tbool isBoomerang(vector<vector<int>>& points) {\n\t\t\tif(points.size() != 3)\n\t\t\t\treturn false;\n\n\t\t\t// formula for slope = (y2 - y1)/(x2 - x1)\n\t\t\t// assume the slope of the line using points 0 and 1 (a/b) and that of using points 0 and 2 (c / d)\n\t\t\t// avoid dividing, just compare a/b and c/d if(a * d > c * b)==> first fraction is greater otherwise second\n\t\t\t// if slopes of the both lines (p0--p1 and p0--p2) are equal then three points form a straight line (cannot form a triangle)\n\t\t\treturn ((points[1][1] - points[0][1]) * (points[2][0] - points[0][0])) != ((points[2][1] - points[0][1]) * (points[1][0] - points[0][0]));\n\t\t}\n\t}; | 22 | 2 | [] | 3 |
valid-boomerang | [Java/Python 3] one liner - slopes of 2 edges are not equal. | javapython-3-one-liner-slopes-of-2-edges-6j7i | If the 3 points can form a triangle ABC, then the slopes of any 2 edges, such as AB and AC, are not equal.\n\nUse Formula as follows:\n\n(y0 - y1) / (x0 - x1) ! | rock | NORMAL | 2019-05-05T04:03:01.884186+00:00 | 2020-04-12T17:32:52.774133+00:00 | 2,139 | false | If the 3 points can form a triangle ABC, then the slopes of any 2 edges, such as AB and AC, are not equal.\n\nUse Formula as follows:\n\n(y0 - y1) / (x0 - x1) != (y0 - y2) / (x0 - x2) => \n\n(x0 - x2) * (y0 - y1) != (x0 - x1) * (y0 - y2)\n\nWhere \nA:\nx0 = p[0][0]\ny0 = p[0][1]\nB:\nx1 = p[1][0]\ny1 = p[1][1]\nC:\nx2 = p[2][0]\ny2 = p[2][1]\n\n**Use the muliplication form to cover corner cases such as, a slope is infinity, 2 or 3 points are equal.**\n\n```java\n public boolean isBoomerang(int[][] p) {\n return (p[0][0] - p[2][0]) * (p[0][1] - p[1][1]) != (p[0][0] - p[1][0]) * (p[0][1] - p[2][1]);\n }\n```\n```python\n def isBoomerang(self, p: List[List[int]]) -> bool:\n return (p[0][0] - p[2][0]) * (p[0][1] - p[1][1]) != (p[0][0] - p[1][0]) * (p[0][1] - p[2][1])\n``` | 21 | 1 | [] | 2 |
valid-boomerang | 🔥🔥Boomerang Check: Detecting Collinearity in 2D Points||Easy Solution🔥🔥 | boomerang-check-detecting-collinearity-i-x1ir | Intuition\n Describe your first thoughts on how to solve this problem. \nThe approach involves using the formula for the slope of a line to determine if the giv | Aashiq_Edavalapati | NORMAL | 2024-04-21T07:38:21.711434+00:00 | 2024-04-21T07:38:21.711467+00:00 | 993 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe approach involves using the formula for the slope of a line to determine if the given three points are collinear. For three points (x1, y1), (x2, y2), and (x3, y3), the slope of the line between (x1, y1) and (x2, y2) can be represented as (y2 - y1) / (x2 - x1). If the slopes between consecutive pairs of points are not equal, then the points are not collinear, and hence they form a boomerang.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Calculate the slopes between consecutive pairs of points:\n - For (x1, y1) to (x2, y2): slope1 = (y2 - y1) / (x2 - x1)\n - For (x2, y2) to (x3, y3): slope2 = (y3 - y2) / (x3 - x2)\n2. If the slopes are not equal, the points are not collinear and hence form a boomerang.\n3. But there is a corner case of division by zero. So, cross multiply the denominators of the slopes and check equality of:\n```\n (y2-y1)*(x3-x2) != (y3-y2)*(x2-x1)\n```\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of this solution is $$O(1)$$, as it involves constant-time operations (calculations of differences and multiplications) for the given three points.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity is also $$O(1)$$, as we are not using any additional space that scales with the input size, only basic variables to store intermediate results.\n\n# Code\n```java []\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return (points[1][1]-points[0][1])*(points[2][0]-points[1][0]) != (points[2][1]-points[1][1])*(points[1][0]-points[0][0]); \n }\n}\n```\n```python3 []\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n return (points[1][1]-points[0][1])*(points[2][0]-points[1][0]) != (points[2][1]-points[1][1])*(points[1][0]-points[0][0])\n```\n\n\n | 20 | 0 | ['Math', 'Java', 'Python3'] | 0 |
valid-boomerang | O(1) Valid Boomerang Solution in C++ | o1-valid-boomerang-solution-in-c-by-the_-bo8r | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nSlopes are matched : (y | The_Kunal_Singh | NORMAL | 2023-05-08T05:06:44.412131+00:00 | 2023-05-08T05:07:36.468883+00:00 | 1,303 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSlopes are matched : (y2-y1)/(x2-x1)\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(1)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n float a,b,c,d;\n a = (points[1][1]-points[0][1]);\n b = (points[1][0]-points[0][0]);\n c = (points[2][1]-points[1][1]);\n d = (points[2][0]-points[1][0]);\n if((b!=0 && d!=0 && a*d==b*c) || (b==0 && d==0 && points[0][0]==points[1][0]))\n {\n return false;\n }\n if((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]))\n {\n return false;\n }\n return true;\n }\n};\n```\n\n | 13 | 0 | ['C++'] | 0 |
valid-boomerang | Python, math solution, checking slopes | python-math-solution-checking-slopes-by-y1e7g | \nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n (x0, y0), (x1, y1), (x2, y2) = points\n return (y2 - y1) * (x0 - | blue_sky5 | NORMAL | 2020-10-19T03:33:59.357801+00:00 | 2020-10-19T04:20:04.039730+00:00 | 1,306 | false | ```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n (x0, y0), (x1, y1), (x2, y2) = points\n return (y2 - y1) * (x0 - x1) != (x2 - x1) * (y0 - y1)\n``` | 11 | 1 | ['Python', 'Python3'] | 0 |
valid-boomerang | [c++] Full explanation(100% faster) || Using triangle rule | c-full-explanation100-faster-using-trian-8xjd | Example : [1,1] [2,3] [3,2]\nLets say:\n\n(x1,y1) = (1,1) \n(x2,y2) = (2,3) \n(x3,y3) = (3,2)\n\nif slopes of lines with any two point will be same , then they | Ved_Prakash1102 | NORMAL | 2021-01-11T07:00:30.274761+00:00 | 2021-01-12T03:32:57.707168+00:00 | 743 | false | **Example : [1,1] [2,3] [3,2]**\nLets say:\n```\n(x1,y1) = (1,1) \n(x2,y2) = (2,3) \n(x3,y3) = (3,2)\n```\n**if slopes of lines with any two point will be same , then they are in straight line**\ni.e.\n```\nL1 = (points[0][0] - points[1][0])/(points[0][1]-points[1][1]);\nL2 = (points[0][0] - points[2][0])/(points[0][1]-points[2][1]);\n```\n```\n(y2\u2212y1)/(x2\u2212x1) = (y3\u2212y1)/(x3\u2212x1)\nL1 = L2\n```\n* But if denominator is 0 then slope gives infinite value which is difficult to compare.\n\n**Solution to above difficulty :**\nCross multiplication method comes with no error hence we will use that :)\n```\n (y2\u2212y1)*(x3\u2212x1) = (y3\u2212y1)*(x2\u2212x1)\n````\n\t\n* so now if equal then not valid boomerang i.e they are in straight line\n If not equal then they are valid boomerang i.e not in straight line*\n\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n \n int LHS = (points[0][0] - points[1][0])*(points[0][1]-points[2][1]);\n int RHS = (points[0][0] - points[2][0])*(points[0][1]-points[1][1]);\n \n if(LHS == RHS) {\n return false;\n }\n return true;\n }\n};\n``` | 8 | 1 | ['C', 'C++'] | 0 |
valid-boomerang | Java 0ms solution | java-0ms-solution-by-spoorthi_raj-wqia | The above question makes it clear that a valid boomerang is a triangle. To find out if the given three points form a valid boomerang or not,we calculate the are | spoorthi_raj | NORMAL | 2019-06-21T16:56:41.002765+00:00 | 2019-06-21T16:56:41.002811+00:00 | 978 | false | The above question makes it clear that a valid boomerang is a triangle. To find out if the given three points form a valid boomerang or not,we calculate the area enclosed by those three points.Non zero area represents a valid boomerang.\n\n\nCode:\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n if(Math.abs((points[0][0]-points[1][0])*(points[1][1]-points[2][1])-(points[1][0]-points[2][0])*(points[0][1]-points[1][1]))!=0)\n return true;\n return false;\n }\n}\n```\n | 8 | 1 | [] | 4 |
valid-boomerang | Java | Math | Faster Than 100% Java Submissions | java-math-faster-than-100-java-submissio-uy51 | \nclass Solution {\n public boolean isBoomerang(int[][] p) {\n int x1=p[0][0];\n int y1=p[0][1];\n int x2=p[1][0];\n int y2=p[1][ | Divyansh__26 | NORMAL | 2022-09-07T06:19:57.082653+00:00 | 2022-09-07T06:19:57.082711+00:00 | 1,241 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] p) {\n int x1=p[0][0];\n int y1=p[0][1];\n int x2=p[1][0];\n int y2=p[1][1];\n int x3=p[2][0];\n int y3=p[2][1];\n int area=x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);\n return area!=0;\n }\n}\n```\nKindly upvote if you like the code. | 7 | 0 | ['Math', 'Java'] | 0 |
valid-boomerang | Simple Python code: calculate the line equation (with explanation) | simple-python-code-calculate-the-line-eq-2mnm | \n def isBoomerang(self, points):\n x0, y0 = points[0][0], points[0][1]\n x1, y1 = points[1][0], points[1][1]\n x2, y2 = points[2][0], poin | dr_sean | NORMAL | 2019-05-06T19:41:17.424336+00:00 | 2019-05-06T20:34:19.032851+00:00 | 685 | false | ```\n def isBoomerang(self, points):\n x0, y0 = points[0][0], points[0][1]\n x1, y1 = points[1][0], points[1][1]\n x2, y2 = points[2][0], points[2][1]\n if [x0, y0] == [x1, y1] or [x0, y0] == [x2, y2] or [x1, y1] == [x2, y2]: return False\n if x0 == x1 == x2: return False\n if x0 == x1: return True\n a = float(y0 - y1) / float(x0 - x1)\n b = y0 - a * x0\n if y2 == a * x2 + b: return False\n else: return True\n```\n\n**Explanations:**\n**Main idea:**\nCalculate the line equation between the first two points (x0,y0) & (x1,y1), and check if the third point (x2,y2) is not located on this line.\n\n- The line equation: Y = a * X + b\n- The slop (a) is calculated as: a = (y1 - y0) / (x1 - x0)\n- The y-intercept (b) is calculated as: b = y0 - a * x0\n- If the point (x2,y2) is not located on the line, return True; Otherwise, return False.\n\n**Extreme cases:**\n- If any of the two points are the same, it means that we actually have two points, and there are always a line between two points; therefore the code should return the False value:\n```\n (1,1)\n\n(0,0)(0,0)\n\nwhich is equivalent to:\n (1,1)\n\n(0,0)\n```\n- If x0 = x1 = x2, it means that all three points are located on one line; As a result, the code should return the False value:\n```\n(0,0) (1,0) (2,0)\n```\n- If x0 = x1, the denominator in the calculation of the slope (a) will be zero. However, this means that the first and second points are on one line, but the third point is not; Therefore, the code return the True value:\n```\n(0,1) (1,1)\n\n(0,0)\n```\n | 7 | 2 | [] | 1 |
valid-boomerang | Simple Slope based approach O(1) | simple-slope-based-approach-o1-by-christ-3pnp | Slope of line going through (x1, y1) and (x2, y2) = (y1 - y2)/(x1 - x2)\nTwo lines are same if their slope is same\nso (y1 - y2)/(x1 - x2) = (y1- y3)/(x1 - x3) | christris | NORMAL | 2019-05-05T04:39:26.265608+00:00 | 2019-05-05T04:39:26.265651+00:00 | 457 | false | Slope of line going through (x1, y1) and (x2, y2) = (y1 - y2)/(x1 - x2)\nTwo lines are same if their slope is same\nso (y1 - y2)/(x1 - x2) = (y1- y3)/(x1 - x3)\nor (y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2); \nNot condition added as problem asks for if points are NOT on same line.\n\n``` csharp\npublic class Solution \n{\n public bool IsBoomerang(int[][] points) \n\t{\n int x1 = points[0][0];\n int y1 = points[0][1];\n \n int x2 = points[1][0];\n int y2 = points[1][1];\n \n int x3 = points[2][0];\n int y3 = points[2][1]; \n \n \n return (y1 - y2) * (x1 - x3) != (y1 - y3) * (x1 - x2); \n \n }\n}\n``` | 6 | 1 | [] | 0 |
valid-boomerang | Compare slopes python | compare-slopes-python-by-sunakshi132-tjop | To avoid division by zero instead of comparing (delta y1)/(delta x1) != (delta y2)/(delta x2), cross multiply: (delta y1) * (delta x2) != (delta y2) * (delta x1 | sunakshi132 | NORMAL | 2022-08-01T23:21:19.293922+00:00 | 2022-08-01T23:23:35.996164+00:00 | 892 | false | To avoid division by zero instead of comparing (delta y1)/(delta x1) != (delta y2)/(delta x2), cross multiply: (delta y1) * (delta x2) != (delta y2) * (delta x1)\n\n```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n a,b,c=points\n return (b[1]-a[1])*(c[0]-b[0]) != (c[1]-b[1])*(b[0]-a[0])\n``` | 5 | 0 | ['Python', 'Python3'] | 0 |
valid-boomerang | Cross product | cross-product-by-interpunctus-vj2j | Cross product or vector product is another way:\n\n public bool IsBoomerang(int[][] points) {\n var x1 = points[0][0] - points[1][0]; \n var y1 | interpunctus | NORMAL | 2019-05-11T09:12:17.060185+00:00 | 2019-05-11T09:12:17.060230+00:00 | 529 | false | Cross product or vector product is another way:\n```\n public bool IsBoomerang(int[][] points) {\n var x1 = points[0][0] - points[1][0]; \n var y1 = points[0][1] - points[1][1]; \n var x2 = points[0][0] - points[2][0]; \n var y2 = points[0][1] - points[2][1]; \n return (x1*y2 - x2*y1) != 0;\n }\n```\nVector product is zero when the vectors are linearly dependent. Geometrically speaking its magnitude is the area of a parallelogram made with the vectors. | 5 | 1 | [] | 0 |
valid-boomerang | 💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 💯 | easiestfaster-lesser-cpython3javacpython-0stz | Intuition\n\n\n\n\n\n\nC++ []\nclass Solution {\npublic:\n static bool isBoomerang(vector<vector<int>>& points) {\n int x1 = points[0][0], y1 = points | Edwards310 | NORMAL | 2024-06-08T12:55:28.964555+00:00 | 2024-06-08T12:55:28.964588+00:00 | 928 | false | # Intuition\n\n\n\n\n\n\n```C++ []\nclass Solution {\npublic:\n static bool isBoomerang(vector<vector<int>>& points) {\n int x1 = points[0][0], y1 = points[0][1];\n int x2 = points[1][0], y2 = points[1][1];\n int x3 = points[2][0], y3 = points[2][1];\n return (x1 * y2 - x1 * y3) + (y1 * x3 - y1 * x2) + (x2 * y3 - x3 * y2);\n }\n};\n\nauto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return \'c\';\n}();\n```\n```python3 []\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n 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])\n```\n```C []\nbool isBoomerang(int** points, int pointsSize, int* pointsColSize) {\n int x1 = points[0][0], y1 = points[0][1];\n int x2 = points[1][0], y2 = points[1][1];\n int x3 = points[2][0], y3 = points[2][1];\n return y1 * (x3 - x2) + y2 * (x1 - x3) + y3 * (x2 - x1);\n}\n```\n```java []\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n boolean condition = ((points[0][0] * (points[1][1] - points[2][1]))\n + (points[1][0] * (points[2][1] - points[0][1])) + (points[2][0] * (points[0][1] - points[1][1]))) != 0;\n return condition;\n }\n}\n```\n```python []\nclass Solution(object):\n def isBoomerang(self, points):\n """\n :type points: List[List[int]]\n :rtype: bool\n """\n x1, y1 = points[0]\n x2, y2 = points[1]\n x3, y3 = points[2] \n area = abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))\n return area != 0\n \n```\n```C# []\npublic class Solution {\n public bool IsBoomerang(int[][] points) {\n int x1 = points[0][0], y1 = points[0][1];\n int x2 = points[1][0], y2 = points[1][1];\n int x3 = points[2][0], y3 = points[2][1];\n return (y1 * (x3 - x2) + y2 * (x1 - x3) + y3 * (x2 - x1)) != 0;\n }\n}\n```\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n O(1)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n O(1)\n# Code\n```\nclass Solution(object):\n def isBoomerang(self, points):\n """\n :type points: List[List[int]]\n :rtype: bool\n """\n x1, y1 = points[0]\n x2, y2 = points[1]\n x3, y3 = points[2] \n area = abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))\n return area != 0\n \n```\n\n | 4 | 0 | ['Array', 'Math', 'Geometry', 'C', 'Python', 'C++', 'Java', 'Python3', 'C#'] | 0 |
valid-boomerang | 1 Line || Java Solution | 1-line-java-solution-by-rtkush-4500 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | RtLavKush7 | NORMAL | 2024-03-18T15:13:16.861484+00:00 | 2024-03-18T15:13:16.861510+00:00 | 1,020 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return !((points[0][0]-points[1][0])*(points[0][1]-points[2][1])==(points[0][0]-points[2][0])*(points[0][1]-points[1][1]));\n }\n}\n``` | 4 | 1 | ['Java'] | 0 |
valid-boomerang | ✅EASY C++ NAIVE SOLUTION & BETTER ALGORITHM | 100% FASTER | easy-c-naive-solution-better-algorithm-1-tfpz | Algorithm 1:\n1. Calculate differences between points\n2. Cross multiply \n\ta. Second y-axis difference with first x-axis difference\n\tb. First y-axis differe | ke4e | NORMAL | 2022-07-23T18:20:10.895801+00:00 | 2022-07-23T18:20:10.895851+00:00 | 395 | false | Algorithm 1:\n1. Calculate differences between points\n2. Cross multiply \n\ta. Second y-axis difference with first x-axis difference\n\tb. First y-axis difference with second x-axis difference\n3. If they will be equal, it will return false(i.e. straight line) otherwise true (boomerang)\nNote: On cross multiplying, it automatically removed zero error.\n\nAlgorithm 2:\n1. Calculate area of triangle using those coordinates.\n2. If area is equal to 0, it means that it will form straight line otherwise boomerang\n\nYou can try whatever solution you like. No worry if first solution striked first in your mind, that\'s a good start, keep it up. \n\nThank you for reading. Please upvote if you like my solution.\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n if (points.size()<=2) return false;\n int x0=points[0][0], y0=points[0][1];\n int x1=points[1][0], y1=points[1][1];\n int x2=points[2][0], y2=points[2][1];\n int dx1=x1-x0, dy1=y1-y0;\n int dx2=x2-x1, dy2=y2-y1;\n if (dy1*dx2==dy2*dx1) return false;\n return true;\n }\n};\n``` | 4 | 0 | ['C'] | 0 |
valid-boomerang | just a simple solution by just using area of triangle || 0ms runtime | just-a-simple-solution-by-just-using-are-s81x | \nclass Solution {\n public boolean isBoomerang(int[][] p) {\n int x1=p[0][0];\n int y1=p[0][1];\n \n int x2=p[1][0];\n in | Rakesh_Sharma_4 | NORMAL | 2022-01-23T01:30:31.322670+00:00 | 2022-01-23T01:34:21.713328+00:00 | 124 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] p) {\n int x1=p[0][0];\n int y1=p[0][1];\n \n int x2=p[1][0];\n int y2=p[1][1];\n \n int x3=p[2][0];\n int y3=p[2][1];\n \n int area=x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);\n return area!=0;\n }\n}\n``` | 4 | 6 | ['Java'] | 1 |
valid-boomerang | 100 % Beats || Simple || One Line of Code | 100-beats-simple-one-line-of-code-by-kdh-v1xt | IntuitionApproachComplexity
Time complexity:O(1)
Space complexity:O(1)
Code | kdhakal | NORMAL | 2025-03-26T15:22:16.368786+00:00 | 2025-03-26T15:22:16.368786+00:00 | 62 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:O(1)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
public boolean isBoomerang(int[][] pt) {
return (pt[0][0] * (pt[1][1] - pt[2][1]) +
pt[1][0] * (pt[2][1] - pt[0][1]) +
pt[2][0] * (pt[0][1] - pt[1][1])) != 0;
}
}
``` | 3 | 0 | ['Java'] | 0 |
valid-boomerang | C++ || sORo | c-soro-by-so-ro-yfid | Intuition\nGive it a dry run, you well get it.\n\n....\nhey you, yes you.. please do vote this up and let leetcode know you are enjoying what you are watching.\ | sorohere | NORMAL | 2023-07-27T11:11:15.800945+00:00 | 2023-07-27T11:11:15.800973+00:00 | 344 | false | # Intuition\nGive it a ```dry run```, you well get it.\n\n....\nhey you, yes you.. please do vote this up and let leetcode know you are enjoying what you are watching.\n\n# Complexity\n- Time complexity: ```O(1)``` Constant Time.\n\n- Space complexity: ```O(1)``` Constant Space. \n\n# Code\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n int x0 = points[0][0], y0 = points[0][1];\n int x1 = points[1][0], y1 = points[1][1];\n int x2 = points[2][0], y2 = points[2][1];\n\n int area = (x0 * (y1-y2)) + (x1 * (y2-y0)) + (x2 * (y0-y1));\n if(!area) return false ;\n return true ;\n }\n};\n``` | 3 | 0 | ['C++'] | 1 |
valid-boomerang | 100% faster || One line || JAVA x GEOMETRY | 100-faster-one-line-java-x-geometry-by-i-9oo1 | Formula\n\n\n\nSo if three points are not collinear then they will be boomerang\n\n\n# Code\n\nclass Solution {\n public boolean isBoomerang(int[][] points) | im_obid | NORMAL | 2023-04-21T05:07:15.858870+00:00 | 2023-04-21T05:07:15.858904+00:00 | 783 | false | # Formula\n\n\n\nSo if three points are not ```collinear``` then they will be ```boomerang```\n\n\n# Code\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return !((points[0][0]-points[1][0])*(points[0][1]-points[2][1])==(points[0][0]-points[2][0])*(points[0][1]-points[1][1]));\n }\n}\n``` | 3 | 0 | ['Java'] | 1 |
valid-boomerang | Java 0ms solution. with explanation | java-0ms-solution-with-explanation-by-ob-pa6t | Intuition\n Describe your first thoughts on how to solve this problem. \nMy first thought is to check if the three points given form a straight line by checking | Obose | NORMAL | 2023-01-19T17:21:15.055284+00:00 | 2023-01-19T17:21:15.055330+00:00 | 1,176 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy first thought is to check if the three points given form a straight line by checking the slope between each pair of points. If the slope between any two points is the same, then the points form a straight line and are not a boomerang.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMy approach is to first check if any of the three points are the same. If they are, then it is not a boomerang. Then, I will check the slope between each pair of points and see if they are the same. If they are, then it is not a boomerang. If the slope between each pair of points is not the same, then it is a boomerang.\n# Complexity\n- Time complexity: $$O(1)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int x1 = points[0][0];\n int y1 = points[0][1];\n int x2 = points[1][0];\n int y2 = points[1][1];\n int x3 = points[2][0];\n int y3 = points[2][1];\n if ((x1 == x2 && y1 == y2) || (x2 == x3 && y2 == y3) || (x1 == x3 && y1 == y3)) {\n return false;\n }\n if ((x1 - x2) * (y3 - y2) == (x3 - x2) * (y1 - y2)) {\n return false;\n }\n return true;\n }\n}\n``` | 3 | 0 | ['Java'] | 1 |
valid-boomerang | 1 line 100% runtime | 1-line-100-runtime-by-hurshidbek-yjma | \nPLEASE UPVOTE IF YOU LIKE.\n\n```\nreturn ( p[0][0] - p[1][0]) * (p[1][1] - p[2][1] ) !=\n ( p[1][0] - p[2][0]) * (p[0][1] - p[1][1] );\n | Hurshidbek | NORMAL | 2022-07-28T08:49:30.973210+00:00 | 2022-08-20T13:28:52.758954+00:00 | 514 | false | ```\nPLEASE UPVOTE IF YOU LIKE.\n```\n```\nreturn ( p[0][0] - p[1][0]) * (p[1][1] - p[2][1] ) !=\n ( p[1][0] - p[2][0]) * (p[0][1] - p[1][1] );\n | 3 | 0 | ['Array', 'Java'] | 0 |
valid-boomerang | valid-boomerang Java Solution | valid-boomerang-java-solution-by-nishant-n2c7 | ```java\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int a = points[1][1]-points[0][1];\n int b = points[1][0]-points[0][ | nishant7372 | NORMAL | 2022-02-27T10:24:24.732785+00:00 | 2022-02-27T10:24:24.732824+00:00 | 214 | false | ```java\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int a = points[1][1]-points[0][1];\n int b = points[1][0]-points[0][0];\n int c = points[2][1]-points[1][1];\n int d = points[2][0]-points[1][0];\n if((a*d)!=(b*c))\n return true;\n return false;\n } \n} | 3 | 0 | [] | 0 |
valid-boomerang | Rust solution | rust-solution-by-bigmih-b9hi | We can use formula:\n\n\nimpl Solution {\n pub fn is_boomerang(p: Vec<Vec<i32>>) -> bool {\n let (x0, y0) = (p[0][0], p[0][1]);\n let (x1, y1) | BigMih | NORMAL | 2021-10-19T05:14:16.061182+00:00 | 2021-10-19T05:14:16.061220+00:00 | 149 | false | We can use formula:\n\n```\nimpl Solution {\n pub fn is_boomerang(p: Vec<Vec<i32>>) -> bool {\n let (x0, y0) = (p[0][0], p[0][1]);\n let (x1, y1) = (p[1][0], p[1][1]);\n let (x2, y2) = (p[2][0], p[2][1]);\n\n ((x0 - x1) * (y2 - y1) - (x2 - x1) * (y0 - y1)).abs() > 0\n }\n}\n``` | 3 | 0 | ['Math', 'Rust'] | 1 |
valid-boomerang | [C++] Solutions | c-solutions-by-zxspring21-j7p0 | C++:\n(1) Intuition\n\nbool isBoomerang(vector<vector<int>>& points) {\n\tset<double> slope;\n\tfor(int i=0;i<3;++i){\n\t\tif(points[i%3][0]==points[(i+1)%3][0] | zxspring21 | NORMAL | 2020-10-13T02:31:00.192133+00:00 | 2020-10-13T02:32:50.496822+00:00 | 220 | false | ##### **C++:**\n**(1) Intuition**\n```\nbool isBoomerang(vector<vector<int>>& points) {\n\tset<double> slope;\n\tfor(int i=0;i<3;++i){\n\t\tif(points[i%3][0]==points[(i+1)%3][0]) slope.insert(DBL_MAX);\n\t\telse slope.insert( (double)(points[i][1]-points[(i+1)%3][1])/ (points[i][0]-points[(i+1)%3][0]) );\n\t}\n\treturn slope.size()==3;\n}\n```\n**(2) slopeAB != slopeAC**\n(points[0][1]-points[1][1]) / (points[0][0]-points[1][0]) != (points[0][1]-points[2][1]) / (points[0][0]-points[2][0])\n=> `(points[0][1]-points[1][1]) * (points[0][0]-points[2][0]) != (points[0][1]-points[2][1]) * (points[0][0]-points[1][0])`\n```\nbool isBoomerang(vector<vector<int>>& points) {\n\treturn (points[0][1]-points[1][1]) * (points[0][0]-points[2][0]) != (points[0][1]-points[2][1]) * (points[0][0]-points[1][0]);\n}\n```\n**(3) triangle area != 0**\nProof: `xa(yb-yc) + xb(yc-ya) + xc(ya-yb)`\n\nSabc = Saob + Sboc + Scoa\n = 1/2*(xb-xa)(yc-yb) + 1/2* (xc-xb)(ya-yc) + 1/2(xc-xb)(yc-yb)\n = 1/2 (xayb + xbyc+ xcya- xayc - xcyb- xbya)\n = 1/2 (xa(yb-yc) + xb(yc-ya) + xc(ya-yb))\n \n```\nbool isBoomerang(vector<vector<int>>& points) {\n\treturn 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])!=0;\n}\n```\n | 3 | 0 | ['C'] | 0 |
valid-boomerang | Java comparing slope | java-comparing-slope-by-hobiter-888y | \n //make sure slope is not the same;\n // (a[1] - b[1]) / (a[0] - b[0]) != (c[1] - b[1]) / (c[0] - b[0]) \n // to avoid divid by zero error, transfer | hobiter | NORMAL | 2020-09-14T05:18:13.056236+00:00 | 2020-09-14T05:18:13.056293+00:00 | 259 | false | ```\n //make sure slope is not the same;\n // (a[1] - b[1]) / (a[0] - b[0]) != (c[1] - b[1]) / (c[0] - b[0]) \n // to avoid divid by zero error, transfer to:\n // (a[1] - b[1]) * (c[0] - b[0]) != (c[1] - b[1]) * (a[0] - b[0])\n public boolean isBoomerang(int[][] ps) {\n int[] a = ps[0], b = ps[1], c = ps[2];\n return (a[1] - b[1]) * (c[0] - b[0]) != (c[1] - b[1]) * (a[0] - b[0]);\n }\n``` | 3 | 0 | [] | 0 |
valid-boomerang | C++ | 4ms | 100% | Triangle Area | c-4ms-100-triangle-area-by-tushleo96-csch | \nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n int x1 = points[0][0] ;\n int y1 = points[0][1] ;\n \n | tushleo96 | NORMAL | 2020-05-24T21:05:32.079154+00:00 | 2020-05-24T21:05:32.079190+00:00 | 267 | false | ```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n int x1 = points[0][0] ;\n int y1 = points[0][1] ;\n \n int x2 = points[1][0] ;\n int y2 = points[1][1] ;\n \n int x3 = points[2][0] ;\n int y3 = points[2][1] ;\n \n int area = x1*(y2-y3) - y1*(x2-x3) + (x2*y3 - x3*y2) ;\n \n if(area==0) return false ;\n return true ;\n \n }\n};\n``` | 3 | 0 | ['Math', 'C++'] | 0 |
valid-boomerang | Python 99.14% finding the distance between points | python-9914-finding-the-distance-between-p6en | \nclass Solution(object):\n def isBoomerang(self, points):\n """\n :type points: List[List[int]]\n :rtype: bool\n """\n A, | denyscoder | NORMAL | 2019-09-06T19:52:43.717991+00:00 | 2019-09-06T19:54:03.340914+00:00 | 475 | false | ```\nclass Solution(object):\n def isBoomerang(self, points):\n """\n :type points: List[List[int]]\n :rtype: bool\n """\n A, B, C = points\n AB = ((A[0] - B[0])**2 + (A[1] - B[1])**2)**(0.5)\n BC = ((B[0] - C[0])**2 + (B[1] - C[1])**2)**(0.5)\n AC = ((A[0] - C[0])**2 + (A[1] - C[1])**2)**(0.5)\n return not(AB == BC + AC or BC == AB + AC or AC == AB + BC)\n``` | 3 | 3 | ['Math', 'Python', 'Python3'] | 0 |
valid-boomerang | Check the colinearlity condition of coordinate geometry . | check-the-colinearlity-condition-of-coor-5l3a | Intuitioncheck the collinearlity condition of the linesApproachsteps :
for three points (x1,y1),(x2,y2),(x3,y3) will be collinear if they
(y2-y1) x ( x3-x2) = ( | abhisheks02 | NORMAL | 2025-03-31T20:52:49.859136+00:00 | 2025-03-31T20:52:49.859136+00:00 | 30 | false | # Intuition
check the collinearlity condition of the lines
# Approach
steps :
for three points (x1,y1),(x2,y2),(x3,y3) will be collinear if they
(y2-y1) x ( x3-x2) = (y3-y2) x ( x2 - x1) .
Upvote krna nahi bhulna bro !
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```cpp []
class Solution {
public:
bool isBoomerang(vector<vector<int>>& points) {
int x1 =points[0][0] ;
int y1 = points[0][1] ;
int x2 = points[1][0] ;
int y2 = points[1][1] ;
int x3 = points[2][0] ;
int y3 = points[2][1];
return ( y2 - y1)*(x3-x2) != (y3-y2) * (x2-x1);
}
};
``` | 2 | 0 | ['C++'] | 0 |
valid-boomerang | EASY C++ 100% O(1) AREA | easy-c-100-o1-area-by-hnmali-t2jw | Complexity
Time complexity: O(1)
Aux. Space: O(1)
Code | hnmali | NORMAL | 2025-02-26T16:31:51.532364+00:00 | 2025-02-26T16:31:51.532364+00:00 | 123 | false |
# Complexity
- Time complexity: $$O(1)$$
- Aux. Space: $$O(1)$$
# Code
```cpp []
class Solution {
public:
bool isBoomerang(vector<vector<int>>& pt) {
int area = pt[0][0] * (pt[1][1] - pt[2][1]) +
pt[1][0] * (pt[2][1] - pt[0][1]) +
pt[2][0] * (pt[0][1] - pt[1][1]);
return (area != 0);
}
};
``` | 2 | 0 | ['Array', 'Math', 'Geometry', 'C++'] | 0 |
valid-boomerang | Best Approach.. | In O(1) Time Complexity..🚀 | best-approach-in-o1-time-complexity-by-m-hr1h | Intuition\nI saw the concept of colinearity of the triangle and just applied the formula for area of triangle..\n\n# Approach\nFind out the area of triangle and | mansimittal935 | NORMAL | 2024-06-27T15:14:57.235102+00:00 | 2024-06-27T15:14:57.235131+00:00 | 62 | false | # Intuition\nI saw the concept of colinearity of the triangle and just applied the formula for area of triangle..\n\n# Approach\nFind out the area of triangle and match if it is equal to zero or not..\n\n# Complexity\n- Time complexity:\n- O(1)\n\n- Space complexity:\n- O(1)\n\n# Code\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n int x1 = points[0][0];\n int y1 = points[0][1];\n\n int x2 = points[1][0];\n int y2 = points[1][1];\n \n int x3 = points[2][0];\n int y3 = points[2][1];\n \n double area = abs(x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2))/2.0;\n\n if(area == 0)\n {\n return false;\n }\n return true;\n }\n};\n``` | 2 | 0 | ['C++'] | 0 |
valid-boomerang | Easy one liner Java Solution | easy-one-liner-java-solution-by-ansh29-gqtk | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | AnsH29 | NORMAL | 2024-02-05T16:42:04.600408+00:00 | 2024-02-05T16:42:04.600426+00:00 | 530 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int x1 = points[0][0];\n int x2 = points[1][0];\n int x3 = points[2][0];\n int y1 = points[0][1];\n int y2 = points[1][1];\n int y3 = points[2][1];\n int ans = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);\n\n return ans != 0;\n }\n}\n``` | 2 | 0 | ['Java'] | 0 |
valid-boomerang | Maths Concept of Collinierity | maths-concept-of-collinierity-by-yashraj-p07g | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Yashrajsingh282 | NORMAL | 2023-10-26T15:29:21.984666+00:00 | 2023-10-26T15:29:21.984684+00:00 | 389 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return !((points[0][0]-points[1][0])*(points[0][1]-points[2][1])==(points[0][0]-points[2][0])*(points[0][1]-points[1][1]));\n }\n}\n``` | 2 | 0 | ['Java'] | 0 |
valid-boomerang | O(1) | o1-by-deleted_user-szsp | \n# Code\n\n/**\n * @param {number[][]} points\n * @return {boolean}\n */\nvar isBoomerang = function(points) {\n // x1 (y2 - y3) + x2 (y3 - y1) + x3 (y1 - y | deleted_user | NORMAL | 2023-07-16T18:40:51.909129+00:00 | 2023-07-16T18:40:51.909147+00:00 | 223 | false | \n# Code\n```\n/**\n * @param {number[][]} points\n * @return {boolean}\n */\nvar isBoomerang = function(points) {\n // x1 (y2 - y3) + x2 (y3 - y1) + x3 (y1 - y2) = 0\n let [[x1, y1], [x2, y2], [x3, y3]] = points\n return x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) == 0 ? false : true\n};\n``` | 2 | 0 | ['JavaScript'] | 0 |
valid-boomerang | Python Super Easy | python-super-easy-by-h2k4082k-lp1h | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | h2k4082k | NORMAL | 2023-01-30T14:57:39.426134+00:00 | 2023-01-30T14:57:39.426183+00:00 | 1,245 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n x1, y1 = points[0][0], points[0][1]\n x2, y2 = points[1][0], points[1][1]\n x3, y3 = points[2][0], points[2][1]\n # slope between 1 and 2\n slope12 = 0\n if x2 - x1 == 0:\n slope12 = 90\n else:\n slope12 = (y2 - y1) / (x2 - x1)\n \n # slope between 1 and 3\n slope13 = 0\n if x3 - x1 == 0:\n slope13 = 90\n else:\n slope13 = (y3 - y1) / (x3 - x1)\n \n # slope between 2 and 3\n slope23 = 0\n if x3 - x2 == 0:\n slope23 = 90\n else:\n slope23 = (y3 - y2) / (x3 - x2)\n\n if slope12 == slope13 or slope12 == slope23 or slope13 == slope23:\n return False\n return True\n\n``` | 2 | 0 | ['Python3'] | 1 |
valid-boomerang | Easy to understand || C++ | easy-to-understand-c-by-yashwardhan24_sh-saer | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yashwardhan24_sharma | NORMAL | 2023-01-02T06:09:00.855085+00:00 | 2023-01-02T06:09:00.855130+00:00 | 1,137 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n int x1 , x2 ,x3 , y1,y2,y3 , m1 , m2;\n x1 = points[0][0]; x2 = points[1][0]; x3 = points[2][0];\n y1 = points[0][1]; y2 = points[1][1]; y3 = points[2][1]; \n\n int area;\n area = (x1*y2) - (x1*y3) - (y1*x2) + (y1*x3) + (x2*y3)-(y2*x3);\n if(area)\n return true;\n return false; \n }\n};\n``` | 2 | 0 | ['C++'] | 1 |
valid-boomerang | Easy and Well Understandable - C++ Beats 100% Efficient (Using only if statement) | easy-and-well-understandable-c-beats-100-ev2s | Code\n\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n int x1 = points[0][0] ;\n int y1 = points[0][1] ;\n | abhishektirkey | NORMAL | 2023-01-01T15:27:39.751230+00:00 | 2023-01-01T15:27:39.751275+00:00 | 1,259 | false | # Code\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n int x1 = points[0][0] ;\n int y1 = points[0][1] ;\n \n int x2 = points[1][0] ;\n int y2 = points[1][1] ;\n \n int x3 = points[2][0] ;\n int y3 = points[2][1] ;\n \n int area = x1*(y2-y3) - y1*(x2-x3) + (x2*y3 - x3*y2) ;\n \n if(area==0) return false ;\n return true ;\n \n }\n};\n``` | 2 | 0 | ['C++'] | 0 |
valid-boomerang | c++ | 100% faster | easy | c-100-faster-easy-by-venomhighs7-c5c1 | \n\n# Code\n\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n return (p[0][0] - p[1][0]) * (p[0][1] - p[2][1]) != (p[0][0] | venomhighs7 | NORMAL | 2022-11-17T04:54:07.240065+00:00 | 2022-11-17T04:54:07.240129+00:00 | 835 | false | \n\n# Code\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n return (p[0][0] - p[1][0]) * (p[0][1] - p[2][1]) != (p[0][0] - p[2][0]) * (p[0][1] - p[1][1]);\n }\n};\n``` | 2 | 0 | ['C++'] | 0 |
valid-boomerang | One Liner : Using Equation Of Line | one-liner-using-equation-of-line-by-ashu-u9lh | //Check Weather the points follow the equation of line or not if it follow return false else return true\nThe Equation of line is shown in figure you can see it | Ashutosh_2002 | NORMAL | 2022-09-22T13:55:13.051858+00:00 | 2022-09-22T13:55:13.051903+00:00 | 442 | false | //Check Weather the points follow the equation of line or not if it follow return false else return true\nThe Equation of line is shown in figure you can see it and understood easly \n\n\n\n``` \n bool isBoomerang(vector<vector<int>>& points) {\n \n return (points[2][1] - points[0][1])*(points[1][0] - points[0][0]) != (points[1][1] - points[0][1])*(points[2][0] - points[0][0]);\n \n }\n``` | 2 | 0 | [] | 0 |
valid-boomerang | 【Hex】Python - Math | hex-python-math-by-hexuanweng-731z | Solution\nFormula: (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1)\n\npython\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n | HexuanWeng | NORMAL | 2022-06-08T13:02:42.275969+00:00 | 2022-06-08T13:02:42.275999+00:00 | 305 | false | ## Solution\nFormula: (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1)\n\n```python\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n (x1, y1), (x2, y2), (x3, y3) = points\n return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1)\n``` | 2 | 0 | ['Math'] | 0 |
valid-boomerang | ✅ [C] || Simple Solution || O(1) | c-simple-solution-o1-by-bezlant-hgxw | \n\nThis is our formula, but we can\'t keep the "/" division to avoid dividing by ZERO.\n(y2 - y1) / (x2 - x1) != (y3 - y2) / (x3 - x2)\nSo it comes down to\n(y | bezlant | NORMAL | 2022-04-14T06:28:28.631041+00:00 | 2022-04-14T06:28:28.631086+00:00 | 129 | false | \n\nThis is our formula, but we can\'t keep the "/" division to avoid dividing by ***ZERO***.\n**(y2 - y1) / (x2 - x1) != (y3 - y2) / (x3 - x2)**\n*So it comes down to*\n**(y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1)**\n\n```\nbool isBoomerang(int** points, int pointsSize, int* pointsColSize){\n return (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]) !=\n (points[2][1] - points[1][1]) * (points[1][0] - points[0][0]);\n}\n```\n\n**If this was helpful, don\'t hesitate to upvote! :)**\nHave a nice day! | 2 | 0 | ['C'] | 0 |
valid-boomerang | Java Easy Solution | java-easy-solution-by-osb-379h | \nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int x1 = points[0][0];\n int y1 = points[0][1];\n int x2 = points[1 | osb | NORMAL | 2022-03-08T08:40:58.573137+00:00 | 2022-03-08T08:40:58.573163+00:00 | 201 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int x1 = points[0][0];\n int y1 = points[0][1];\n int x2 = points[1][0];\n int y2 = points[1][1];\n int x3 = points[2][0];\n int y3 = points[2][1];\n \n if((y2-y1) * (x3-x2) != (x2-x1) * (y3-y2)){\n return true;\n }\n return false;\n }\n}\n``` | 2 | 0 | ['Math', 'Java'] | 0 |
valid-boomerang | Simple & Easy One Line Solution by Python 3 | simple-easy-one-line-solution-by-python-77ihg | \nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n return (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]) != | jamesujeon | NORMAL | 2022-01-15T09:17:51.402464+00:00 | 2022-01-15T09:27:46.023282+00:00 | 192 | false | ```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n return (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]) != (points[2][1] - points[1][1]) * (points[1][0] - points[0][0])\n```\n\nWhen the points are expressed like:\n- `(x0, y0) = (points[0][0], points[0][1])`\n- `(x1, y1) = (points[1][0], points[1][1])`\n- `(x2, y2) = (points[2][0], points[2][1])`\n\nIf you compare slopes of them, you can know the slopes are in a straight line or not.\n- Slope 1: `(y1 - y0) / (x1 - x0)`\n- Slope 2: `(y2 - y1) / (x2 - x1)`\n- Compare the slopes: `(y1 - y0) / (x1 - x0) != (y2 - y1) / (x2 - x1)`\n\nBut, there could be the division by zero in the expression.\nTo avoid it, you can convert it to `(y1 - y0) * (x2 - x1) != (y2 - y1) * (x1 - x0)`. | 2 | 0 | ['Python3'] | 0 |
valid-boomerang | Easy C++ solution | easy-c-solution-by-imran2018wahid-sipd | \nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n // Check wheather the points are distinct or not\n if(points[0] | imran2018wahid | NORMAL | 2021-12-26T07:51:53.182607+00:00 | 2021-12-26T07:51:53.182637+00:00 | 239 | false | ```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n // Check wheather the points are distinct or not\n if(points[0]==points[1] || points[1]==points[2] || points[2]==points[0]) {\n return false;\n }\n \n // Calculate the area of the triangle formed by the three points. If area is a non-zero value, the points are not in a straight line.\n int f=points[0][0]*points[1][1]+points[1][0]*points[2][1]+points[2][0]*points[0][1];\n int s=points[0][1]*points[1][0]+points[1][1]*points[2][0]+points[2][1]*points[0][0];\n int area=abs(f-s);\n return area!=0;\n }\n};\n```\n***Please upvote if you have got any help from my code. Thank you.*** | 2 | 0 | ['C'] | 0 |
valid-boomerang | c++|Math|Geometry | cmathgeometry-by-abdullahalrifat-zs38 | we just need to calculate the area of triangle with this 3 coordinates. if the total area is greater than 0 then it is boomerang else not.\narea = the absolute | abdullahalrifat | NORMAL | 2021-12-07T06:14:23.052085+00:00 | 2021-12-07T06:14:23.052120+00:00 | 213 | false | we just need to calculate the area of triangle with this 3 coordinates. if the total area is greater than 0 then it is boomerang else not.\n**area = the absolute value of Ax(By - Cy) + Bx(Cy - Ay) + Cx(Ay - By) divided by 2**\n```\nfloat area = abs((float)(points[0][0]*(points[1][1]-points[2][1])) +\n (float)(points[1][0]*(points[2][1]-points[0][1])) +\n (float)(points[2][0]*(points[0][1]-points[1][1])))/2;\n if(area > 0) return true;\n else return false; | 2 | 0 | ['Geometry', 'C'] | 0 |
valid-boomerang | Rust - Colinearity check [0ms 2MB] | rust-colinearity-check-0ms-2mb-by-dimtio-o540 | Underlying idea: if two vectors are colinear, their scalar product is equal to the product of their norm\n\nrust\nimpl Solution {\n pub fn is_boomerang(point | dimtion | NORMAL | 2021-06-08T03:26:30.122987+00:00 | 2021-06-10T05:03:54.859036+00:00 | 109 | false | Underlying idea: if two vectors are colinear, their scalar product is equal to the product of their norm\n\n```rust\nimpl Solution {\n pub fn is_boomerang(points: Vec<Vec<i32>>) -> bool {\n let a = (points[1][0] - points[0][0], points[1][1] - points[0][1]);\n let b = (points[2][0] - points[0][0], points[2][1] - points[0][1]);\n \n let scl = a.0 * b.0 + a.1 * b.1;\n let norm_a = (a.0 * a.0 + a.1 * a.1);\n let norm_b = (b.0 * b.0 + b.1 * b.1);\n // <a,b> == |a| * |b| <=> a and b are colinear\n return norm_a > 0 && norm_b > 0 && scl * scl != norm_a * norm_b;\n }\n}\n```\n | 2 | 0 | ['Rust'] | 0 |
valid-boomerang | C++ Solution using Slope Formula | c-solution-using-slope-formula-by-themat-pn5g | \n bool isBoomerang(vector<vector<int>>& points) {\n return (((points[1][1]-points[0][1]) * (points[2][0]-points[0][0])) != ((points[2][1]-points[0][1 | TheMatrixNeo | NORMAL | 2021-04-04T08:17:57.196118+00:00 | 2021-04-04T08:17:57.196155+00:00 | 117 | false | ```\n bool isBoomerang(vector<vector<int>>& points) {\n return (((points[1][1]-points[0][1]) * (points[2][0]-points[0][0])) != ((points[2][1]-points[0][1]) * (points[1][0]-points[0][0])));\n }\n``` | 2 | 0 | [] | 0 |
valid-boomerang | Simple Solution in Java | 100% Faster | simple-solution-in-java-100-faster-by-s3-qnr3 | Checking if the points are collinear or not - by checking if sum of distance between any two points equal to the other. If they are linear (i.e. satisfies above | s34 | NORMAL | 2021-02-17T00:49:50.055218+00:00 | 2021-02-17T00:52:25.488163+00:00 | 117 | false | Checking if the points are collinear or not - by checking if sum of distance between any two points equal to the other. If they are linear (i.e. satisfies above condition) such point exists, then it is a valid boomerang.\n\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n double d1=Math.sqrt(Math.pow((points[0][0]-points[2][0]),2)+Math.pow((points[0][1]-points[2][1]),2));\n double d2=Math.sqrt(Math.pow((points[0][0]-points[1][0]),2)+Math.pow((points[0][1]-points[1][1]),2));\n double d3=Math.sqrt(Math.pow((points[1][0]-points[2][0]),2)+Math.pow((points[1][1]-points[2][1]),2));\n \n return ((d1+d2==d3)||(d2+d3==d1)||(d1+d3==d2))?false:true;\n }\n}\n```\nPlease **upvote**, if you like the solution:) | 2 | 0 | [] | 0 |
valid-boomerang | My Python Solution | my-python-solution-by-vatamaniuk-fn6y | Hey guys, here\'s my solution for the problem.\n\n\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n\t\t#assigning the variables l | vatamaniuk | NORMAL | 2021-01-10T19:21:11.216484+00:00 | 2021-01-10T19:21:56.901877+00:00 | 120 | false | Hey guys, here\'s my solution for the problem.\n\n```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n\t\t#assigning the variables like this just makes it that much more readable imo\n [x1,y1],[x2,y2],[x3,y3] = points\n\t\t#i found this formula for area of a triangle with cartestian coordinates online\n\t\t#if the three coordinates form a triangle instead of a line (boomerang), the area will be greater than 0.\n triangle_area = 0.5*(x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2))\n \n return bool(triangle_area)\n``` | 2 | 0 | [] | 0 |
valid-boomerang | Javascript | One liner | javascript-one-liner-by-surajjadhav7-ttad | \nvar isBoomerang = function([[ax,ay],[bx,by],[cx,cy]]) {\n return ((by-ay)*(cx-bx)!==(cy-by)*(bx-ax));\n};\n | surajjadhav7 | NORMAL | 2020-10-05T06:57:31.534539+00:00 | 2020-10-05T06:57:31.534583+00:00 | 424 | false | ```\nvar isBoomerang = function([[ax,ay],[bx,by],[cx,cy]]) {\n return ((by-ay)*(cx-bx)!==(cy-by)*(bx-ax));\n};\n``` | 2 | 0 | ['JavaScript'] | 1 |
valid-boomerang | Python | Area of triangle | beats 100% | python-area-of-triangle-beats-100-by-anu-5o5p | \nclass Solution:\n def isBoomerang(self, points: List[List[int]]):\n (x1,y1), (x2,y2), (x3,y3) = points\n return x1*(y2-y3) + x2*(y3-y1) + x3* | anuraggupta29 | NORMAL | 2020-09-23T06:45:09.197036+00:00 | 2020-09-23T06:45:09.197081+00:00 | 163 | false | ```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]):\n (x1,y1), (x2,y2), (x3,y3) = points\n return x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2)\n``` | 2 | 0 | [] | 1 |
valid-boomerang | 1 liner cpp solution | 1-liner-cpp-solution-by-bitrish-mbor | If the triangle area formed by three points is 0 then they are collinear.\n\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n retur | bitrish | NORMAL | 2020-09-16T15:31:54.228129+00:00 | 2020-09-16T15:31:54.228190+00:00 | 189 | false | If the triangle area formed by three points is 0 then they are collinear.\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n return (p[0][0]*(p[1][1]-p[2][1]) - p[0][1]*(p[1][0]-p[2][0]) +(p[1][0]*p[2][1] - p[2][0]*p[1][1]))?true:false;\n }\n};\n``` | 2 | 0 | ['Math', 'C', 'C++'] | 0 |
valid-boomerang | simple python 🐍 solution beats Time 95% and Space 100% with comments | simple-python-solution-beats-time-95-and-ft5v | \nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n #staright line if all x similar, all y similiar , or stairs [same cordin | injysarhan | NORMAL | 2020-04-28T23:01:23.836930+00:00 | 2020-04-28T23:02:10.904890+00:00 | 298 | false | ```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n #staright line if all x similar, all y similiar , or stairs [same cordinates all of points] or 2 points are the same\n\t\t\n x1,y1=points[0][0],points[0][1]\n x2,y2=points[1][0],points[1][1]\n x3,y3=points[2][0],points[2][1]\n \n\t\t#case: if 2 points are the same\n if [x1,y1]==[x2,y2] or [x1,y1]==[x3,y3] or [x3,y3]==[x2,y2]:\n return False\n \n\t\t#case: if all X cordinates or All Y Coordinates are the same \n if (x1==x2 and x1==x3) or (y1==y2 and y1==y3):\n return False\n \n\t\t#stair case\n if x1==y1 and x2==y2 and x3==y3:\n return False\n return True\n```\n | 2 | 5 | ['Python', 'Python3'] | 1 |
valid-boomerang | Javascript and C++ solutions | javascript-and-c-solutions-by-claytonjwo-jhb5 | Synopsis:\n\nCompare the slope of the first/second points and the first/third points. If they are not equal, then return true since the 3 points are not on the | claytonjwong | NORMAL | 2020-04-21T23:17:01.430996+00:00 | 2020-04-21T23:17:31.401634+00:00 | 163 | false | **Synopsis:**\n\nCompare the slope of the first/second points and the first/third points. If they are *not* equal, then return `true` since the 3 points are *not* on the same line, otherwise return `false`.\n\n---\n\n**1-liners:**\n\n*Javascript*\n```\nlet isBoomerang = A => (A[0][0] - A[1][0]) * (A[0][1] - A[2][1]) != (A[0][0] - A[2][0]) * (A[0][1] - A[1][1]);\n```\n\n*C++*\n```\nclass Solution {\npublic:\n using VI = vector<int>;\n using VVI = vector<VI>;\n bool isBoomerang(VVI& A) {\n return (A[0][0] - A[1][0]) * (A[0][1] - A[2][1]) != (A[0][0] - A[2][0]) * (A[0][1] - A[1][1]);\n }\n};\n```\n\n---\n\n**Verbose Solutions:** I first created the solutions below, then I refactored them to create the 1-liner solutions above.\n\n*Javascript*\n```\nlet isBoomerang = A => {\n let [[x1, y1], [x2, y2], [x3, y3]] = A;\n return (x1 - x2) * (y1 - y3) != (x1 - x3) * (y1 - y2);\n};\n```\n\n*C++*\n```\nclass Solution {\npublic:\n using VI = vector<int>;\n using VVI = vector<VI>;\n bool isBoomerang(VVI& A) {\n auto [x1, y1] = tie(A[0][0], A[0][1]);\n auto [x2, y2] = tie(A[1][0], A[1][1]);\n auto [x3, y3] = tie(A[2][0], A[2][1]);\n return (x1 - x2) * (y1 - y3) != (x1 - x3) * (y1 - y2);\n }\n};\n```\n | 2 | 0 | [] | 0 |
valid-boomerang | java one line beats 100% | java-one-line-beats-100-by-yanglin0883-0fj5 | math formula\n"\'\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return (points[0][1] - points[1][1]) * (points[1][0] - points[2][ | yanglin0883 | NORMAL | 2019-11-16T01:38:03.400573+00:00 | 2019-11-16T01:38:03.400614+00:00 | 344 | false | math formula\n"\'\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return (points[0][1] - points[1][1]) * (points[1][0] - points[2][0]) !=(points[1][1] - points[2][1]) * (points[0][0] - points[1][0]);\n }\n}\n\'" | 2 | 0 | [] | 0 |
valid-boomerang | One Line Code,Easy to understand | one-line-codeeasy-to-understand-by-tt294-w1l5 | \n\npublic boolean isBoomerang(int[][] points) {\n\t\treturn (points[0][0] - points[1][0]) * (points[0][1] - points[2][1]) \n\t\t\t\t!= (points[0][0] - points[2 | tt294127003 | NORMAL | 2019-08-15T06:20:58.146237+00:00 | 2019-08-15T06:20:58.146657+00:00 | 162 | false | \n```\npublic boolean isBoomerang(int[][] points) {\n\t\treturn (points[0][0] - points[1][0]) * (points[0][1] - points[2][1]) \n\t\t\t\t!= (points[0][0] - points[2][0]) * (points[0][1] - points[1][1]);\n\t}\n``` | 2 | 1 | [] | 0 |
valid-boomerang | python solution | python-solution-by-ram_code-e5he | slope formula: y2-y1/x2-x1\n\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n X,Y,Z = points\n x1,y1 = X\n x | ram_code | NORMAL | 2019-05-21T00:25:30.281443+00:00 | 2019-05-21T00:35:42.864081+00:00 | 257 | false | **slope formula:** y2-y1/x2-x1\n```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n X,Y,Z = points\n x1,y1 = X\n x2,y2 = Y\n x3,y3 = Z\n return (X != Y or Y != Z or X != Z) and (y2-y1)*(x3-x2) != (y3-y2)*(x2-x1)\n``` | 2 | 1 | [] | 2 |
valid-boomerang | One line Java solution beats 100% | one-line-java-solution-beats-100-by-arju-uubs | We just need to check if the slopes are different. \ny0 - y1 / x0 - x1 != y0 - y2 / x0 - x2;\nbut 0/0 gives NaN hence we perform cross multiplication.\n\n\n\tpu | arjun_sharma | NORMAL | 2019-05-09T05:15:04.994117+00:00 | 2019-05-09T05:18:40.646251+00:00 | 215 | false | We just need to check if the slopes are different. \ny0 - y1 / x0 - x1 != y0 - y2 / x0 - x2;\nbut 0/0 gives NaN hence we perform cross multiplication.\n\n```\n\tpublic boolean isBoomerang(int[][] points) {\n return (points[0][1] - points[1][1]) * (points[0][0] - points[2][0]) != (points[0][1] - points[2][1]) * (points[0][0] - points[1][0]);\n }\n``` | 2 | 1 | [] | 0 |
valid-boomerang | JavaScript beats 98.77% (rearranged slopes formula) | javascript-beats-9877-rearranged-slopes-3e6rv | If the two slopes are different, it is a boomerang. \nBut just simply calculating and comparing slopes can cause divide by zero issues.\n\nJust cross multipy th | beroa | NORMAL | 2019-05-07T01:00:48.704889+00:00 | 2019-05-07T01:00:48.704953+00:00 | 276 | false | If the two slopes are different, it is a boomerang. \nBut just simply calculating and comparing slopes can cause divide by zero issues.\n\nJust cross multipy the compare slopes formula: \n( y1-y0 / x1-x0 ) == ( y2-y1 / x2-x1 ) turns into ( y1-y0 )*( x2-x1 ) == ( x1-x0 )( y2-y1 ) \n\n```\n\tif ((points[1][1] - points[0][1]) * (points[2][0] - points[1][0]) == \n (points[1][0] - points[0][0]) * (points[2][1] - points[1][1])) {\n return false\n } else {\n return true\n }\n``` | 2 | 1 | [] | 1 |
valid-boomerang | Simple Java Solution (Rearrange slope check to avoid division by zero) | simple-java-solution-rearrange-slope-che-sbul | \nclass Solution {\n public boolean isBoomerang(int[][] points) {\n if ((points[1][1]-points[0][1])*(points[2][0]-points[0][0])==(points[2][1]-points[ | akashur | NORMAL | 2019-05-06T10:54:33.708419+00:00 | 2019-05-06T10:54:33.708463+00:00 | 249 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n if ((points[1][1]-points[0][1])*(points[2][0]-points[0][0])==(points[2][1]-points[0][1])*(points[1][0]-points[0][0]))\n return false;\n return true;\n \n }\n}\n```\nSlope betwwen two points: (y1-y0)/(x1-x0)\nFor three collinear points:\n(y1-y0)/(x1-x0)=(y2-y0)/(x2-x0)\nOR\n(y1-y0)*(x2-x0)=(y2-y0)*(x1-x0) | 2 | 1 | [] | 0 |
valid-boomerang | Java one line solution | java-one-line-solution-by-zzz-clgp | start with calculating the slopes to any two lines formed by two points:\n\n public boolean isBoomerang(int[][] points) {\n if ((points[0][0] == point | zzz_ | NORMAL | 2019-05-05T07:02:53.124784+00:00 | 2019-05-05T07:11:39.291109+00:00 | 174 | false | start with calculating the slopes to any two lines formed by two points:\n```\n public boolean isBoomerang(int[][] points) {\n if ((points[0][0] == points[1][0] && points[0][1] == points[1][1]) || (points[1][0] == points[2][0] && points[1][1] == points[2][1])) return false;\n return (double) (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]) != (double) (points[2][1] - points[1][1]) / (points[2][0] - points[1][0]);\n }\n```\nbecause there might be two points overlapped, so to make it simpler to avoid arithmatic exception (divide by 0) and also the case like `[[1,1],[2,2],[999,1000]]`, so do the following:\n```\n public boolean isBoomerang1(int[][] points) {\n return (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]) != (points[2][1] - points[1][1]) * (points[1][0] - points[0][0]);\n }\n``` | 2 | 1 | [] | 0 |
valid-boomerang | 1 Line Java.(Orientation) | 1-line-javaorientation-by-poorvank-b8bc | Refer this.\n\n\n public boolean isBoomerang(int[][] points) {\n return ((points[1][1]-points[0][1])*(points[2][0]-points[1][0]) - (points[1][0]-points[0 | poorvank | NORMAL | 2019-05-05T04:01:49.769419+00:00 | 2019-05-05T04:05:23.628558+00:00 | 264 | false | Refer [this](https://www.geeksforgeeks.org/orientation-3-ordered-points/).\n\n```\n public boolean isBoomerang(int[][] points) {\n return ((points[1][1]-points[0][1])*(points[2][0]-points[1][0]) - (points[1][0]-points[0][0])*(points[2][1]-points[1][1]))!=0;\n }\n``` | 2 | 2 | [] | 0 |
valid-boomerang | Simple 1-liner || Beats 100% | simple-1-liner-beats-100-by-vidhaan_j-95gr | IntuitionApproachComplexity
Time complexity: O(1)
Space complexity: O(1)
Code | Vidhaan_J | NORMAL | 2025-03-17T00:57:35.822967+00:00 | 2025-03-17T00:57:35.822967+00:00 | 57 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. --> I already knew the formula x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)!=0. So I just had to plug the points in.
# Approach
<!-- Describe your approach to solving the problem. --> I just plugged the points in with the formula.
# Complexity
- Time complexity: O(1)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```python3 []
class Solution:
def isBoomerang(self, points: List[List[int]]) -> bool:
return 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])!=0
``` | 1 | 1 | ['Math', 'Python', 'Python3'] | 0 |
valid-boomerang | ✅ 🔥 Beats 100% 🔥|| easy pizzy ✅ ||4 line code ✅ || O(1) || | beats-100-easy-pizzy-4-line-code-o1-by-k-0kq1 | Code | Krupa_133 | NORMAL | 2025-01-21T06:30:15.800337+00:00 | 2025-01-21T06:30:15.800337+00:00 | 171 | false | 
# Code
```python3 []
class Solution:
def isBoomerang(self, points: List[List[int]]) -> bool:
if points[0]==points[1] or points[0] == points[2] or points[1] == points[2]:
return False
if (points[1][0]-points[0][0]) == 0:
if points[2][0]==points[0][0]:
return False
else:
return True
if (points[2][0]-points[1][0]) == 0:
if points[0][0]==points[1][0]:
return False
else:
return True
slant1 = (points[1][1]-points[0][1])/(points[1][0]-points[0][0])
slant2 = (points[2][1]-points[1][1])/(points[2][0]-points[1][0])
return (slant1)!=(slant2)
``` | 1 | 0 | ['Python3'] | 0 |
valid-boomerang | Simple C solution | simple-c-solution-by-mukesh1855-kir6 | \n# Approach\n Describe your approach to solving the problem. \nUsing simple geometry formula\n\n\n# Code\nc []\nbool isBoomerang(int** points, int pointsSize, | mukesh1855 | NORMAL | 2024-12-06T20:36:19.255699+00:00 | 2024-12-06T20:36:19.255759+00:00 | 43 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing simple geometry formula\n\n\n# Code\n```c []\nbool isBoomerang(int** points, int pointsSize, int* pointsColSize) {\n int x1 = points[0][0];\n int x2 = points[1][0];\n int x3 = points[2][0];\n int y1 = points[0][1];\n int y2 = points[1][1];\n int y3 = points[2][1];\n\n double area = 0.5* abs((x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2)));\n\n return area!=0;\n}\n``` | 1 | 0 | ['C'] | 0 |
valid-boomerang | Easy⚡O(1)🗿simple solution💡with step by step procedure with | easyo1simple-solutionwith-step-by-step-p-x3wp | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | shamnad_skr | NORMAL | 2024-11-27T15:49:50.439825+00:00 | 2024-11-27T15:49:50.439876+00:00 | 99 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```typescript []\nfunction isBoomerang(points: number[][]): boolean {\n\n\n //destructuring for readability\n const [x1 , y1] = points[0];\n const [x2 , y2] = points[1];\n const [x3 , y3] = points[2];\n\n //if any of piont is same return false\n\n if( (x1 === x2 && y1 === y2) ||\n (x2 === x3 && y2 === y3) ||\n (x3 === x1 && y3 === y1) ){\n\n return false ;\n }\n\n //checking for its in same line or not \n\n if( (y2 - y1) * (x3 - x2) === (y3 - y2) * (x2-x1) ){\n return false;\n }\n\n return true;\n\n \n};\n``` | 1 | 0 | ['TypeScript', 'JavaScript'] | 0 |
valid-boomerang | Easy solution | easy-solution-by-harshitaggarwal026-9n5c | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | harshitagg14 | NORMAL | 2024-09-10T19:22:16.422708+00:00 | 2024-09-10T19:22:16.422740+00:00 | 118 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n boolean condition = ((points[0][0] * (points[1][1] - points[2][1]))\n + (points[1][0] * (points[2][1] - points[0][1])) + (points[2][0] * (points[0][1] - points[1][1]))) != 0;\n return condition;\n }\n}\n``` | 1 | 0 | ['Java'] | 0 |
valid-boomerang | Simple java code 0 ms beats 100 % | simple-java-code-0-ms-beats-100-by-arobh-oxt0 | \n# Complexity\n\n# Code\n\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int xm012=points[1][1]-points[0][1];\n xm012=xm01 | Arobh | NORMAL | 2024-03-21T13:28:31.964497+00:00 | 2024-03-21T13:28:31.964520+00:00 | 133 | false | \n# Complexity\n\n# Code\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int xm012=points[1][1]-points[0][1];\n xm012=xm012*(points[2][0]-points[1][0]);\n int ym012=points[2][1]-points[1][1];\n ym012=ym012*(points[1][0]-points[0][0]);\n if(xm012==ym012) return false;\n\n return true;\n }\n}\n``` | 1 | 0 | ['Array', 'Math', 'Geometry', 'Java'] | 0 |
valid-boomerang | C# Solution | c-solution-by-panaeimi-xtf1 | Code\n\npublic class Solution {\n public bool IsBoomerang(int[][] points) {\n int x1 = points[0][0], y1 = points[0][1]; \n int x2 = points[ | panaeimi | NORMAL | 2023-07-05T21:26:50.184091+00:00 | 2023-07-05T21:26:50.184108+00:00 | 27 | false | # Code\n```\npublic class Solution {\n public bool IsBoomerang(int[][] points) {\n int x1 = points[0][0], y1 = points[0][1]; \n int x2 = points[1][0], y2 = points[1][1]; \n int x3 = points[2][0], y3 = points[2][1]; \n\n return (y2 - y1) * (x3 - x1) != (y3- y1) * (x2 - x1); \n }\n }\n``` | 1 | 0 | ['C#'] | 0 |
valid-boomerang | Python solution | python-solution-by-dmitry_nagorniy-c1d3 | Code\n\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n if ((points[2][0] - points[0][0]) * (points[1][1] - points[0][1])) | Dmitry_Nagorniy | NORMAL | 2022-12-25T09:47:57.011806+00:00 | 2022-12-25T09:47:57.011845+00:00 | 102 | false | # Code\n```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n if ((points[2][0] - points[0][0]) * (points[1][1] - points[0][1])) != (points[2][1] - points[0][1]) * (points[1][0] - points[0][0]):\n return 1\n``` | 1 | 0 | ['Python3'] | 0 |
valid-boomerang | 100% fast soln with 98% memory efficiency | 100-fast-soln-with-98-memory-efficiency-ul8k9 | bool isBoomerang(vector>& points) {\n\t\tint x1=points[0][0], x2=points[1][0], x3=points[2][0];\n int y1=points[0][1], y2=points[1][1], y3=points[2][1];\ | jainshreyansh163 | NORMAL | 2022-09-23T16:36:56.011553+00:00 | 2022-09-23T16:36:56.011590+00:00 | 158 | false | bool isBoomerang(vector<vector<int>>& points) {\n\t\tint x1=points[0][0], x2=points[1][0], x3=points[2][0];\n int y1=points[0][1], y2=points[1][1], y3=points[2][1];\n if(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)==0) return false;\n return true;\n } | 1 | 0 | [] | 1 |
valid-boomerang | 📌Fastest & easy Java☕ solution 0ms💯 | fastest-easy-java-solution-0ms-by-saurab-5wy9 | ```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return (points[0][0]-points[1][0])(points[2][1]-points[0][1])!=(points[0][1]-p | saurabh_173 | NORMAL | 2022-06-29T11:44:52.037998+00:00 | 2022-06-29T11:44:52.038029+00:00 | 88 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return (points[0][0]-points[1][0])*(points[2][1]-points[0][1])!=(points[0][1]-points[1][1])*(points[2][0]-points[0][0]);\n }\n} | 1 | 0 | [] | 0 |
valid-boomerang | C# | c-by-neildeng0705-66qe | public bool IsBoomerang(int[][] points) {\n \n \n return points[0][0] * (points[1][1] - points[2][1]) + points[1][0] * (points[2][1] - poi | neildeng0705 | NORMAL | 2022-04-01T22:08:23.538012+00:00 | 2022-04-01T22:08:23.538051+00:00 | 93 | false | public bool IsBoomerang(int[][] points) {\n \n \n return 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]) != 0;\n } | 1 | 0 | [] | 1 |
valid-boomerang | Go area of triangle | go-area-of-triangle-by-dchooyc-m17d | Area of Triangle in Coordinate Geometry\n\n(\u0394ABC) = (1/2) | x1 (y2 \u2013 y3 ) + x2 (y3 \u2013 y1 ) + x3(y1 \u2013 y2) |\n\nIf the three coordinates are a | dchooyc | NORMAL | 2022-03-09T01:50:29.714695+00:00 | 2022-03-09T01:50:29.714728+00:00 | 130 | false | [Area of Triangle in Coordinate Geometry](https://www.cuemath.com/geometry/area-of-triangle-in-coordinate-geometry/)\n\n```(\u0394ABC) = (1/2) | x1 (y2 \u2013 y3 ) + x2 (y3 \u2013 y1 ) + x3(y1 \u2013 y2) |```\n\nIf the three coordinates are along the same line, the area of the three coordinates must be zero.\n\n```\nfunc isBoomerang(points [][]int) bool {\n x1, x2, x3 := points[0][0], points[1][0], points[2][0]\n y1, y2, y3 := points[0][1], points[1][1], points[2][1]\n area := x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2)\n\n return area != 0\n}\n``` | 1 | 0 | ['Go'] | 0 |
valid-boomerang | 100.00% faster and 100.00% less memory in PHP | 10000-faster-and-10000-less-memory-in-ph-im13 | \nfunction isBoomerang($points){\n $a = $points[0][0] - $points[1][0];\n $b = $points[0][1] - $points[1][1];\n $c = $points[0][0] - $points | tusharGore26 | NORMAL | 2022-02-23T12:02:10.425144+00:00 | 2022-02-23T12:02:10.425253+00:00 | 51 | false | ```\nfunction isBoomerang($points){\n $a = $points[0][0] - $points[1][0];\n $b = $points[0][1] - $points[1][1];\n $c = $points[0][0] - $points[2][0];\n $d = $points[0][1] - $points[2][1];\n if($a*$d - $b*$c == 0) return false;\n return true;\n }\n\t``` | 1 | 0 | ['PHP'] | 0 |
valid-boomerang | Easy mathematics solution || Area of triangle | easy-mathematics-solution-area-of-triang-9nnk | If three points are colinear than the area of triangle formed by these points will be zero always.\n\n\nclass Solution:\n def isBoomerang(self, points: List[ | amit_101 | NORMAL | 2022-02-02T22:06:17.848903+00:00 | 2022-02-02T22:08:53.270538+00:00 | 215 | false | If three points are colinear than the area of triangle formed by these points will be zero always.\n\n```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n temp1 = points[0][0]*(points[1][1] - points[2][1]) \n temp2 = points[1][0]*(points[2][1] - points[0][1])\n temp3 = points[2][0]*(points[0][1] - points[1][1])\n \n if (temp1 + temp2 + temp3) != 0:\n return True\n else :\n return False\n``` | 1 | 0 | ['Math', 'Python'] | 0 |
valid-boomerang | c++,easy collinear | ceasy-collinear-by-aksh-99-bwod | ```\nclass Solution {\npublic:\n bool isBoomerang(vector>& p) {\n int t=p[0][0](p[1][1]-p[2][1])+p[1][0](p[2][1]-p[0][1])+p[2][0]*(p[0][1]-p[1][1]);\n | aksh-99 | NORMAL | 2021-12-04T14:58:37.932374+00:00 | 2021-12-04T14:58:37.932400+00:00 | 79 | false | ```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n int t=p[0][0]*(p[1][1]-p[2][1])+p[1][0]*(p[2][1]-p[0][1])+p[2][0]*(p[0][1]-p[1][1]);\n if(t==0)return false;\n return true;\n }\n}; | 1 | 0 | ['Math'] | 0 |
valid-boomerang | Javascript, calculate if points are not collinear | javascript-calculate-if-points-are-not-c-irps | \nconst isBoomerang = p => !isCollinear(...p);\n\nfunction isCollinear(a, b, c) {\n const p1 = [b[0] - a[0], b[1] - a[1]];\n const p2 = [c[0] - a[0], c[1] - a | a8e | NORMAL | 2021-12-01T22:19:03.711664+00:00 | 2021-12-01T22:19:03.711704+00:00 | 155 | false | ```\nconst isBoomerang = p => !isCollinear(...p);\n\nfunction isCollinear(a, b, c) {\n const p1 = [b[0] - a[0], b[1] - a[1]];\n const p2 = [c[0] - a[0], c[1] - a[1]];\n\n return crossProduct(p1, p2) === 0;\n}\n\nfunction crossProduct(p1, p2) {\n return p1[0] * p2[1] - p2[0] * p1[1];\n}\n``` | 1 | 0 | ['JavaScript'] | 1 |
valid-boomerang | C++ Solution | One Line of code ! check collinearity | c-solution-one-line-of-code-check-collin-la2y | \nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& pts) {\n return (pts[0][0]*(pts[1][1]-pts[2][1]))+(pts[1][0]*(pts[2][1]-pts[0][1]) | rac101ran | NORMAL | 2021-10-12T19:48:04.242783+00:00 | 2021-10-12T19:49:20.038628+00:00 | 183 | false | ```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& pts) {\n return (pts[0][0]*(pts[1][1]-pts[2][1]))+(pts[1][0]*(pts[2][1]-pts[0][1]))+(pts[2][0]*(pts[0][1]-pts[1][1]));\n }\n};\n``` | 1 | 0 | ['Math', 'Geometry', 'C'] | 0 |
valid-boomerang | Simple Java solution | simple-java-solution-by-mtuzmen-gfhi | I think this question was very useless. Nevertheless, below is my code. I think it can still be improved for that it can be made more generic to make it work if | mtuzmen | NORMAL | 2021-09-23T21:11:09.509228+00:00 | 2021-09-23T21:11:31.469181+00:00 | 191 | false | I think this question was very useless. Nevertheless, below is my code. I think it can still be improved for that it can be made more generic to make it work if there are more than 3 points. But, I hope it may be helpful for now. Good luck to everybody. \n\n if (points.length != 3 || points[0].length != 2) return false;\n\n int [] xdif = new int[points.length - 1]; \n int [] ydif = new int[points.length - 1]; \n \n for (int i = 1; i < points.length; i++) { \n xdif[i-1] = points[i][0] - points[0][0];\n ydif[i-1] = points[i][1] - points[0][1]; \n }\n return xdif[0] * ydif[1] != xdif[1] * ydif[0]; \n | 1 | 0 | ['Java'] | 0 |
valid-boomerang | Swift | Valid Boomerang | One-liner (Vector Cross Product) | swift-valid-boomerang-one-liner-vector-c-ymr8 | This solution uses the fact that the cross product of two colinear vectors is 0.\nIt subtracts the first point from each of the other points to create two vectr | iosdevzone | NORMAL | 2021-08-31T23:08:53.408689+00:00 | 2021-09-03T17:41:51.614057+00:00 | 150 | false | This solution uses the fact that the cross product of two colinear vectors is 0.\nIt subtracts the first point from each of the other points to create two vectrs and then calculates the cross product between the vectors.\n```swift\nclass Solution {\n func isBoomerang(_ p: [[Int]]) -> Bool {\n (p[1][0]-p[0][0])*(p[2][1]-p[0][1]) - (p[1][1]-p[0][1])*(p[2][0]-p[0][0]) != 0 \n }\n}\n``` | 1 | 0 | ['Swift'] | 0 |
valid-boomerang | Easy C++, formula to check collinearity of three points | easy-c-formula-to-check-collinearity-of-njhi0 | \nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n return((0.5*(p[0][0]*(p[1][1]-p[2][1]) + p[1][0]*(p[2][1]-p[0][1]) + p[2][0 | sharmishtha2401 | NORMAL | 2021-08-28T10:12:20.549757+00:00 | 2021-08-28T10:17:26.244319+00:00 | 144 | false | ```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n return((0.5*(p[0][0]*(p[1][1]-p[2][1]) + p[1][0]*(p[2][1]-p[0][1]) + p[2][0]*(p[0][1]-p[1][1])))!=0);\n }\n};\n\n/*\nFormula for area of triangle is : \n0.5 * [x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)]\n if area of triangle is 0, three points are collinear\n */\n``` | 1 | 0 | [] | 0 |
valid-boomerang | java solution(0 ms) | java-solution0-ms-by-user6640dw-smyj | ```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n \n int x1=points[0][0];\n int x2=points[1][0];\n int x3=point | user6640dw | NORMAL | 2021-08-15T14:38:08.665529+00:00 | 2021-08-15T14:38:08.665559+00:00 | 120 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n \n int x1=points[0][0];\n int x2=points[1][0];\n int x3=points[2][0];\n int y1=points[0][1];\n int y2=points[1][1];\n int y3=points[2][1];\n int left=(y3-y1)*(x2-x1);\n int right=(x3-x1)*(y2-y1);\n if(left==right)\n return false;\n return true;\n }\n}\n | 1 | 0 | [] | 0 |
valid-boomerang | Java - vector cross product should not be zero - 0 ms | java-vector-cross-product-should-not-be-k7bg9 | \nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int dx1 = points[1][0] - points[0][0];\n int dy1 = points[1][1] - points[0] | cpp_to_java | NORMAL | 2021-08-05T09:56:35.034483+00:00 | 2021-08-05T09:56:35.034527+00:00 | 66 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n int dx1 = points[1][0] - points[0][0];\n int dy1 = points[1][1] - points[0][1];\n \n int dx2 = points[2][0] - points[0][0];\n int dy2 = points[2][1] - points[0][1];\n \n return (dx1*dy2 != dx2*dy1);\n }\n}\n``` | 1 | 0 | [] | 0 |
valid-boomerang | simple of simple | simple-of-simple-by-seunggabi-dzp1 | python\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n def d(p1, p2):\n dy = p1[1] - p2[1]\n dx = p | seunggabi | NORMAL | 2021-08-04T20:38:51.995581+00:00 | 2021-08-04T20:38:51.995623+00:00 | 160 | false | ```python\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n def d(p1, p2):\n dy = p1[1] - p2[1]\n dx = p1[0] - p2[0]\n \n try:\n return dy / dx\n except:\n return 0\n \n p = points\n if len(set([str(x) for x in p])) == 2:\n return False\n \n if p[0][0] == p[1][0] == p[2][0]:\n return False\n \n if p[0][1] == p[1][1] == p[2][1]:\n return False\n \n d1 = d(p[0], p[1])\n d2 = d(p[1], p[2])\n if d1 == 0 or d2 == 0:\n return True\n \n return d1 != d2 \n``` | 1 | 0 | ['Python'] | 0 |
valid-boomerang | Java 4 line solution | java-4-line-solution-by-yashashvibhadaur-b827 | class Solution {\n public boolean isBoomerang(int[][] points) {\n if(points[0][0](points[1][1]-points[2][1])+points[1][0](points[2][1]-points[0][1])+p | yashashvibhadauria6555 | NORMAL | 2021-07-11T18:43:54.252277+00:00 | 2021-07-11T18:44:26.834611+00:00 | 172 | false | class Solution {\n public boolean isBoomerang(int[][] points) {\n if(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])==0)\n return false;\n else\n return true;\n }\n}\n\n\n**Description:**\nLet P(x1, y1) , Q (x2, y2) and R (x3, y3) are three given points. If the points P, Q and R are collinearity then we must have\nx1 (y2 - y3) + x2 (y3 - y1) + x3 (y1 - y2) = 0 | 1 | 0 | ['Math', 'Java'] | 0 |
valid-boomerang | 🪃 Swift: Valid Boomerang [4 ms, 100%] (+ Test Cases) | swift-valid-boomerang-4-ms-100-test-case-9r5m | Solution at July 6, 2021\n\nswift\nclass Solution {\n func isBoomerang(_ points: [[Int]]) -> Bool {\n guard Set(points).count >= 3 else { return false | AsahiOcean | NORMAL | 2021-07-05T22:33:25.104539+00:00 | 2021-07-05T22:33:25.104578+00:00 | 1,078 | false | **Solution at July 6, 2021**\n\n```swift\nclass Solution {\n func isBoomerang(_ points: [[Int]]) -> Bool {\n guard Set(points).count >= 3 else { return false }\n \n let points = points.map { [Double($0[0] + 1), Double($0[1] + 1)] }\n func f(_ a: Int,_ b: Int,_ c: Int,_ d: Int) -> Double {abs(points[a][b] - points[c][d])}\n \n let _0010 = f(0,0,1,0),\n _0111 = f(0,1,1,1),\n _0020 = f(0,0,2,0),\n _0121 = f(0,1,2,1),\n _1020 = f(1,0,2,0),\n _1121 = f(1,1,2,1)\n \n let r1 = _0010 / _0111,\n r2 = _0020 / _0121,\n r3 = _1020 / _1121\n \n return !(r1 == r2 && r1 == r3)\n }\n}\n```\n\n```swift\nimport XCTest\n\n// Executed 2 tests, with 0 failures (0 unexpected) in 0.007 (0.008) seconds\n\nclass Tests: XCTestCase {\n private let s = Solution()\n func test1() {\n let res = s.isBoomerang([[1,1],[2,3],[3,2]])\n XCTAssertEqual(res, true)\n }\n func test2() {\n let res = s.isBoomerang([[1,1],[2,2],[3,3]])\n XCTAssertEqual(res, false)\n }\n}\n\nTests.defaultTestSuite.run()\n``` | 1 | 0 | ['Swift'] | 0 |
valid-boomerang | C++| EASY TO UNDERSTAND | fast and efficient using determinants | c-easy-to-understand-fast-and-efficient-n7eyq | Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome\n\nclass Sol | aarindey | NORMAL | 2021-06-13T16:34:11.707436+00:00 | 2021-06-13T20:53:19.123070+00:00 | 162 | false | **Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome**\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n int det;\n if(p[0]==p[1]||p[1]==p[2]||p[2]==p[0])\n return false; \n det=p[0][0]*(p[1][1]-p[2][1])-p[0][1]*(p[1][0]-p[2][0])+(p[1][0]*p[2][1]-p[2][0]*p[1][1]);\n return det!=0;\n }\n};\n``` | 1 | 1 | ['Math', 'C'] | 0 |
valid-boomerang | Python3 simple "one-liner" solution | python3-simple-one-liner-solution-by-ekl-em3t | \nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n return (points[1][1]-points[0][1]) * (points[2][0]-points[1][0]) != (poi | EklavyaJoshi | NORMAL | 2021-06-11T02:41:45.041080+00:00 | 2021-06-11T02:52:50.017940+00:00 | 193 | false | ```\nclass Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:\n return (points[1][1]-points[0][1]) * (points[2][0]-points[1][0]) != (points[1][0]-points[0][0]) * (points[2][1]-points[1][1])\n```\n**If you like this solution, please upvote for this** | 1 | 0 | ['Python3'] | 0 |
valid-boomerang | Java solution faster than 100% | java-solution-faster-than-100-by-nandini-nf8u | \nclass Solution {\n public boolean isBoomerang(int[][] coordinates) {\n int y1=coordinates[0][1];\n int x1=coordinates[0][0];\n int y2 | nandini_awtani | NORMAL | 2021-06-06T14:26:04.057854+00:00 | 2021-06-06T14:26:04.057882+00:00 | 111 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] coordinates) {\n int y1=coordinates[0][1];\n int x1=coordinates[0][0];\n int y2=coordinates[1][1];\n int x2=coordinates[1][0];\n for(int i=2;i<coordinates.length;i++)\n {\n int x3 = coordinates[i][0];\n int y3 = coordinates[i][1];\n if ((y1 - y2) * (x2 - x3) == (y2 - y3) * (x1 - x2))\n {\n return false;\n }\n }\n return true;\n }\n}\n``` | 1 | 0 | [] | 1 |
valid-boomerang | Java | 0ms | 100%faster | java-0ms-100faster-by-aish9-p5ui | \nCalculate the area of the triangle: x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) and compare it with zero.\n\nclass Solution {\n public boolean isBoome | aish9 | NORMAL | 2021-06-03T04:23:22.109234+00:00 | 2021-06-03T04:23:22.109274+00:00 | 140 | false | \nCalculate the area of the triangle: x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) and compare it with zero.\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n return 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]) != 0;\n\n }\n}\n``` | 1 | 1 | ['Java'] | 0 |
valid-boomerang | 1 line with explanation in commnbts java | CPP | 1-line-with-explanation-in-commnbts-java-2hgq | JAVA\n\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n /****\n \n Very simple\n 1. We know the line equation p | kanna17vce | NORMAL | 2021-05-17T08:18:53.720373+00:00 | 2021-05-17T08:18:53.720407+00:00 | 155 | false | JAVA\n```\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n /****\n \n Very simple\n 1. We know the line equation passin through points A(x1,y1) and B(x2,y2) as \n y-y1= (y2-y1)*(x-x1)/(x2-x1)\n cross multuply with (x2-x1)\n (y-y1)(x2-x1)=(y2-y1)(x-x1)\n \n rewrite the same after rearranging \n (x1-x2)*(y-y1)==(y1-y2)(x-x1)\n\n now if a third point C(x3,y3) to be on the same line AB then it must satisfy the above equation. \n \n (x1-x2)*(y3-y1)==(y1-y2)(x3-x1)\n \n Our requirement is that all points should not lie on the same straight line..hence\n verifying (x1-x2)*(y3-y1)!=(y1-y2)(x3-x1) will answer the question\n\n \n )\n *****/\n \n \n\n // return (x1-x2)*(y3-y1)!=(y1-y2)*(x3-x1);\n return (points[0][0]-points[1][0])*(points[2][1]-points[0][1])!=(points[0][1]-points[1][1])*(points[2][0]-points[0][0]);\n\n\n }\n}\n```\nCPP\n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& points) {\n /****\n \n Very simple\n 1. We know the line equation passin through points A(x1,y1) and B(x2,y2) as \n y-y1= (y2-y1)*(x-x1)/(x2-x1)\n cross multuply with (x2-x1)\n (y-y1)(x2-x1)=(y2-y1)(x-x1)\n \n rewrite the same after rearranging \n (x1-x2)*(y-y1)==(y1-y2)(x-x1)\n\n now if a third point C(x3,y3) to be on the same line AB then it must satisfy the above equation. \n \n (x1-x2)*(y3-y1)==(y1-y2)(x3-x1)\n \n Our requirement is that all points should not lie on the same straight line..hence\n verifying (x1-x2)*(y3-y1)!=(y1-y2)(x3-x1) will answer the question\n\n \n )\n *****/\n \n \n\n // return (x1-x2)*(y3-y1)!=(y1-y2)*(x3-x1);\n return (points[0][0]-points[1][0])*(points[2][1]-points[0][1])!=(points[0][1]-points[1][1])*(points[2][0]-points[0][0]);\n\n }\n};\n``` | 1 | 0 | ['C++', 'Java'] | 0 |
valid-boomerang | Java Solution Using Slope of Lines | java-solution-using-slope-of-lines-by-de-vgov | \n public boolean isBoomerang(int[][] points) {\n double m1 = (points[1][1] - points[0][1]) * (points[2][0] - points[0][0]);\n double m2 = (points | demon_1997 | NORMAL | 2021-04-28T23:53:22.676461+00:00 | 2021-04-28T23:53:22.676501+00:00 | 156 | false | ```\n public boolean isBoomerang(int[][] points) {\n double m1 = (points[1][1] - points[0][1]) * (points[2][0] - points[0][0]);\n double m2 = (points[2][1] - points[0][1]) * (points[1][0] - points[0][0]);\n return m1 != m2;\n }\n``` | 1 | 0 | [] | 1 |
valid-boomerang | c++(0ms 100%) equation of line | c0ms-100-equation-of-line-by-zx007pi-rvsj | Runtime: 0 ms, faster than 100.00% of C++ online submissions for Valid Boomerang.\nMemory Usage: 10.3 MB, less than 51.56% of C++ online submissions for Valid B | zx007pi | NORMAL | 2021-04-14T13:43:09.820378+00:00 | 2021-04-14T13:46:42.373337+00:00 | 218 | false | Runtime: 0 ms, faster than 100.00% of C++ online submissions for Valid Boomerang.\nMemory Usage: 10.3 MB, less than 51.56% of C++ online submissions for Valid Boomerang.\n**General idea:**\n1. equation of line for three points : (x-x1)/(x2-x1) = (y-y1)/(y2-y1) transform into:\n(x-x1) * (y2-y1) = (y-y1) * (x2-x1) (for delete devision by zero). And check point \n```\nclass Solution {\npublic:\n bool isBoomerang(vector<vector<int>>& p) {\n return (p[2][0]-p[0][0])*(p[1][1]-p[0][1]) != (p[2][1]-p[0][1])*(p[1][0]-p[0][0]); \n }\n};\n```\n | 1 | 0 | ['C', 'C++'] | 0 |
valid-boomerang | Python calculate area of triangle | python-calculate-area-of-triangle-by-mxm-4gdg | Ugly solution. Since False == 0 and True != 0 we can just return the area directly.\npython\n\tdef isBoomerang(self, points: List[List[int]]) -> bool:\n | mxmb | NORMAL | 2021-04-02T00:36:25.817797+00:00 | 2021-04-02T00:41:20.494210+00:00 | 258 | false | Ugly solution. Since `False == 0` and `True != 0` we can just return the area directly.\n```python\n\tdef isBoomerang(self, points: List[List[int]]) -> bool:\n def areaOfTriangle():\n x, y = [point[0] for point in points], [point[1] for point in points]\n return (x[0]*y[1]+x[1]*y[2]+x[2]*y[0]-y[0]*x[1]-y[1]*x[2]-y[2]*x[0])/2\n return areaOfTriangle()\n``` | 1 | 1 | ['Python', 'Python3'] | 0 |
valid-boomerang | JAVA SOLUTION 100 % FASTER | java-solution-100-faster-by-aniket7419-005t | \nclass Solution {\n public boolean isBoomerang(int[][] point) {\n if(point[0][0]==point[1][0]&&point[0][1]==point[1][1])\n return false;\n | aniket7419 | NORMAL | 2021-01-21T18:32:57.998544+00:00 | 2021-01-21T18:32:57.998588+00:00 | 91 | false | ```\nclass Solution {\n public boolean isBoomerang(int[][] point) {\n if(point[0][0]==point[1][0]&&point[0][1]==point[1][1])\n return false;\n if(point[1][0]==point[2][0]&&point[1][1]==point[2][1])\n return false;\n if(point[0][0]==point[2][0]&&point[0][1]==point[2][1])\n return false;\n \n float slope=((float)(point[0][1]-point[1][1]))/(point[0][0]-point[1][0]);\n if(((float)(point[1][1]-point[2][1]))/(point[1][0]-point[2][0])!=slope)\n return true;\n if(((float)(point[0][1]-point[2][1]))/(point[0][0]-point[2][0])!=slope)\n return true;\n return false;\n \n \n }\n}\n``` | 1 | 0 | [] | 0 |
valid-boomerang | [c++ solution] explanation using slope fourmula | c-solution-explanation-using-slope-fourm-nqn2 | we all know the slope fourmula , if slope between points(0) ,points(1) & points(1), points (2) is same then they are in a straight line .\nslope of 2 points :\n | 0x1h0b | NORMAL | 2020-12-07T15:35:48.544511+00:00 | 2020-12-07T15:35:48.544556+00:00 | 103 | false | we all know the slope fourmula , if slope between points(0) ,points(1) & points(1), points (2) is same then they are in a straight line .\nslope of 2 points :\n `( y2-y1) / (x2-x1)` .... here if all 3 points are in straight line if \n \n `(y2-y1) / (x2-x1) = (y3-y2) / (x3-x2)` \n\nso just `return (y2-y1)*(x3-x2) != (y3-y2)*(x2-x1)`\n\n\n```\n bool isBoomerang(vector<vector<int>>& a) {\n return (a[1][1]-a[0][1])*(a[2][0]-a[1][0]) != (a[2][1]-a[1][1])*(a[1][0]-a[0][0]);\n }\n``` | 1 | 1 | ['C'] | 0 |
valid-boomerang | Solution in Java, Using Determinants, 100%, 0ms, with Explanation | solution-in-java-using-determinants-100-jfeuq | \n// Recall the determinant property that for 3 points we can find the area of triangle using determinants\n// Also there is another property that if points are | johnwwk | NORMAL | 2020-11-29T07:44:13.319110+00:00 | 2020-11-29T07:44:28.160568+00:00 | 105 | false | ```\n// Recall the determinant property that for 3 points we can find the area of triangle using determinants\n// Also there is another property that if points are colinear their determinant is zero\n//\n// x y 1\n// | x0 y0 1 |\n// | x1 y1 1 | = x0(y1-y2) - x1(y0-y2) + x2(y0-y1)\n// | x2 y2 1 |\nclass Solution {\n public boolean isBoomerang(int[][] points) {\n \n int determinant = 0;\n \n determinant = (points[0][0])*(points[1][1] -points[2][1] ) -(points[1][0])*(points[0][1] -points[2][1]) + (points[2][0])*(points[0][1] -points[1][1]);\n \n return determinant !=0 ;\n }\n}\n``` | 1 | 0 | [] | 0 |
number-of-ways-to-stay-in-the-same-place-after-some-steps | Very simple and easy to understand java solution | very-simple-and-easy-to-understand-java-0bpo1 | If we choose our dp state as dp[steps][position], from this state we can either:\n Stay. Then we consume one step and stay at the same position => dp[steps-1][p | renato4 | NORMAL | 2019-11-26T02:05:22.540208+00:00 | 2019-11-26T02:08:44.232679+00:00 | 8,744 | false | If we choose our dp state as `dp[steps][position]`, from this state we can either:\n* Stay. Then we consume one step and stay at the same position => `dp[steps-1][position]`\n* Go right. Then we consume one step and go right => `dp[steps-1][position+1]`\n* Go left (if not at position zero). Then we consume one step and go left => `if position > 0 then dp[steps-1][position-1]`\n\nThen our state can be calculated as: `dp[steps][position] = dp[steps-1][position] + dp[steps-1][position+1] + dp[steps-1][position-1] `. \n\nWe can use the case when we have only one step as base case. Those cases are:\n* We are at position zero and with only one step, then there is only one way (stay) => `dp[1][0] = 1`\n* We are at position one and with only one step, then there is only one way (go left) => `dp[1][1] = 1`\n\nNotice that we can only go right as far as many steps we have. For example, for 500 steps, we can only go as far as the position 500th, doesn\'t matter if the arrLen is 99999999. So we use this to avoid memory/time limit. `min(steps,arrLen)`\n\n```\nclass Solution {\n public int numWays(int steps, int arrLen) {\n int maxPos = Math.min(steps,arrLen);\n long[][] dp = new long[steps+1][maxPos+1];\n \n dp[1][0]=1;\n dp[1][1]=1;\n for(int i = 2; i <= steps; i++) {\n for(int j = 0; j < maxPos; j++) {\n dp[i][j] = (dp[i-1][j] + dp[i-1][j+1] + (j>0?dp[i-1][j-1]:0))%1000000007;\n }\n }\n \n return (int)dp[steps][0];\n }\n}\n``` | 124 | 3 | [] | 22 |
number-of-ways-to-stay-in-the-same-place-after-some-steps | [C++] Recursive DP (Memoization) | c-recursive-dp-memoization-by-phoenixdd-yasr | Observation\nWe can use a simple DFS/recursion to form the solution.\nThe key observation is that we can prune all the positions where i>steps as we can never r | phoenixdd | NORMAL | 2019-11-24T04:01:10.365846+00:00 | 2019-11-25T07:52:23.165983+00:00 | 12,593 | false | **Observation**\nWe can use a simple DFS/recursion to form the solution.\nThe key observation is that we can prune all the positions where `i>steps` as we can never reach `0` in that case.\nWe can now use memoization to cache all our answers, the only thing we need to worry about is memory which can be solved by using the observation `i>steps` will return `0` which means `i` will never exceed `steps/2` due to pruning.\n\n**Solution**\n```c++\nstatic int MOD=1e9+7;\nclass Solution {\npublic:\n vector<vector<int>> memo;\n int arrLen;\n int dp(int i, int steps)\n {\n if(steps==0&&i==0) //Base condition\n return 1;\n if(i<0||i>=arrLen||steps==0||i>steps)\t\t\t\t\t//Pruning.\n return 0;\n if(memo[i][steps]!=-1) //If we have already cached the result for current `steps` and `index` get it.\n return memo[i][steps];\n return memo[i][steps]=((dp(i+1,steps-1)%MOD+dp(i-1,steps-1))%MOD+dp(i,steps-1))%MOD; //Either move right, left or stay.\n \n }\n int numWays(int steps, int arrLen) \n {\n memo.resize(steps/2+1,vector<int>(steps+1,-1));\n this->arrLen=arrLen;\n return dp(0,steps);\n }\n};\n```\n**Complexity**\nSpace: `O(steps^2).` This can be reduecd to `O(steps)` by using top-down DP.\nTime: `O(steps^2).` | 112 | 3 | [] | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.