Minimum Cuts to Divide a Circle — LeetCode 2481 Python Solution
- Problem
- #2481
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
The problem
A valid cut in a circle can be: A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or A cut that is represented by a straight line that touches one point on the edge of the circle and its center. Some valid and invalid cuts are shown in the figures below.
Example
- Input
- n = 4
- Output
- 2
- Explanation
- The above figure shows how cutting the circle twice through the middle divides it into 4 equal slices.
Python solution
class Solution:
def numberOfCuts(self, n: int) -> int:
return n if (n > 1 and n & 1) else n >> 1Complexity
| Measure | Complexity |
|---|---|
| Time | O(1) |
| Space | O(1) auxiliary |
Pattern: Math and Number Theory
Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 2481. Minimum Cuts to Divide a Circle is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math and Geometry.
The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2481. Minimum Cuts to Divide a Circle?
- LeetCode 2481. Minimum Cuts to Divide a Circle is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2481. Minimum Cuts to Divide a Circle?
- The Python solution on this page runs in O(1).
- What is the space complexity of LeetCode 2481. Minimum Cuts to Divide a Circle?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2481. Minimum Cuts to Divide a Circle cover?
- LeetCode 2481. Minimum Cuts to Divide a Circle is tagged Geometry and Math on LeetCode.