Given an array of binary integers, suppose these values are kept on the circumference of a circle at an equal distance. We need to tell whether is it possible to draw a regular polygon using only 1s as its vertices and if it is possible then print the maximum number of sides that regular polygon has.
Input : arr = [1, 1, 1, 0, 1, 0] Output : Polygon possible with side length 3 We can draw a regular triangle having 1s as its vertices as shown in below diagram (a). Input : arr = [1, 0, 1, 0, 1, 0, 1, 0, 1, 1] Output : Polygon possible with side length 5 We can draw a regular pentagon having 1s as its vertices as shown in below diagram (b).
We can solve this problem by getting a relation between the number of vertices a possible polygon can have and total number of values in the array. Let a possible regular polygon in circle has K vertices or K sides then it should satisfy two things to be the answer,
If given array size is N, then K should divide N otherwise K vertices can’t divide N vertices in an equally manner to be a regular polygon.
Next thing is there should be one at every vertex of chosen polygon.
After above points, we can see that for solving this problem we need to iterate over divisors of N and then check whether every value of the array at chosen divisor’s distance is 1 or not. If it is 1 then we found our solution. We can iterate over all divisors in O(sqrt(N)) time just by iterating over from 1 to sqrt(N). you can read more about that here.
Polygon possible with side length 5
This article is contributed by Utkarsh Trivedi. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Side of a regular n-sided polygon circumscribed in a circle
- Area of largest Circle inscribe in N-sided Regular polygon
- Apothem of a n-sided regular polygon
- Area of a n-sided regular polygon with given Radius
- Program to find the Perimeter of a Regular Polygon
- Program to find the Circumcircle of any regular polygon
- Length of Diagonal of a n-sided regular polygon
- Area of a n-sided regular polygon with given side length
- Area of a circle inscribed in a regular hexagon
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Check if a circle lies inside another circle or not
- Equation of circle when three points on the circle are given
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Minimum area of a Polygon with three points given
- Minimum Cost Polygon Triangulation