Given the coordinates of 5 2-dimensional points, check if they form a closed T shape. Print ‘Yes’ if they form T shape and ‘No’ otherwise. Note: Coordinates should be distinct and integers.
There are 4-types of T shaped formations possible according to the given conditions:
Input: [[7, 5], [8, 5], [6, 5], [7, 7], [7, 6]] Output: Yes Input: [[0, 0], [1, 0], [2, 0], [1, -1], [1, -2]] Output: Yes
- Consider the first point in the given list as the centre (x, y) (i.e intersection of the two lines that form T-shape).
- Then check if all the points which are needed to form T-shape of which (x, y) is the centre are present in the list of given points or not.
- Check this for all the 4 possible patterns of T-shape.
Repeat this process from step-1 for all points in the list until a solution is found.
Below is the implementation of the above approach:
Time Complexity: O(1)
- How to check if given four points form a square
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Program to check if three points are collinear
- Check whether four points make a parallelogram
- Program to check whether 4 points in a 3-D plane are Coplanar
- Check if two people starting from different points ever meet
- Check whether it is possible to join two points given on circle such that distance between them is k
- Check if four segments form a rectangle
- Check whether a very large number of the given form is a multiple of 3.
- Steps required to visit M points in order on a circular ring of N points
- Minimum number of points to be removed to get remaining points on one side of axis
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Prime points (Points that split a number into two primes)
- Ways to choose three points with distance between the most distant points <= L
- Program to check if the points are parallel to X axis or Y axis
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.