OP 11 March, 2022 - 09:11 PM
(This post was last modified: 11 March, 2022 - 09:12 PM by cyphur23719. Edited 1 time in total.)
You are given N number of coordinates and your task is to find out how many sides are there in the polygon.
Note: coordinates provided in the input will be in sequential form. Consider that all the coordinates make a close polygon.
Input
4
0 0
0 2
2 2
2 0
Output
4
Explanation:
Given N = 4,
As we can imagine, these points will make a square shape and number of sides in the polygon will be 4.
Input
5
0 0
0 3
3 3
3 1
3 0
Output
4
Explanation:
Given N = 5,
The coordinate (3 1) lies on the side made by coordinate (3 0) and (3 3). This will also make a square shape and have 4 sides.
Can use any programming language C/C++/Python/Java/PHP etc.
Note: coordinates provided in the input will be in sequential form. Consider that all the coordinates make a close polygon.
Input
4
0 0
0 2
2 2
2 0
Output
4
Explanation:
Given N = 4,
As we can imagine, these points will make a square shape and number of sides in the polygon will be 4.
Input
5
0 0
0 3
3 3
3 1
3 0
Output
4
Explanation:
Given N = 5,
The coordinate (3 1) lies on the side made by coordinate (3 0) and (3 3). This will also make a square shape and have 4 sides.
Can use any programming language C/C++/Python/Java/PHP etc.