Given two integers N and M, the task is to find the vertex diagonally opposite to the Mth vertex of an N-sided polygon.
Input: N = 6, M = 2
It can be observed from the image above that the vertex opposite to vertex 5 is 2.
Input: N = 8, M = 5
It can be observed from the image above that the vertex opposite to vertex 8 is 1.
Approach: The following two cases need to be considered to solve the given problem:
- If M > N / 2: The vertex will always be M — (N / 2).
- If M ≤ N / 2: The vertex will always be M + (N / 2).
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if every vertex triplet in graph contains two vertices connected to third vertex
- Polygon with maximum sides that can be inscribed in an N-sided regular polygon
- Check if given polygon is a convex polygon or not
- Find the side of the squares which are inclined diagonally and lined in a row
- Diagonally Dominant Matrix
- Print matrix elements diagonally in spiral form
- Print matrix elements from top-left to bottom right in diagonally upward manner
- Find two vertices of an isosceles triangle in which there is rectangle with opposite corners (0, 0) and (X, Y)
- Find the area of quadrilateral when diagonal and the perpendiculars to it from opposite vertices are given
- Position of a person diametrically opposite on a circle
- Time until distance gets equal to X between two objects moving in opposite direction
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Check if roots of a Quadratic Equation are numerically equal but opposite in sign or not
- Find the cordinates of the fourth vertex of a rectangle with given 3 vertices
- Find number of diagonals in n sided convex polygon
- Program to find the Interior and Exterior Angle of a Regular Polygon
- Program to find the Circumcircle of any regular polygon
- Program to find the Perimeter of a Regular Polygon
- Program to find Area of Triangle inscribed in N-sided Regular Polygon
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.