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)
- Minimum changes required to make two arrays identical
- Maximize the product of four factors of a Number
- Find Nth term (A matrix exponentiation example)
- How can competitive programming help you get a job?
- Burst Balloon to maximize coins
- Minimum number of elements to be removed to make XOR maximum
- What coding habits improve timing in coding contest?
- Maximum Possible Product in Array after performing given Operations
- Sum of decimal equivalent of all possible pairs of Binary representation of a Number
- Count strings with consonants and vowels at alternate position
- How to get rid of Java TLE problem
- Triplet with no element divisible by 3 and sum N
- Count number of primes in an array
- Number of prime pairs in an array
- Pairs with GCD equal to one in the given range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.