Minimum Cuts to Divide a Circle - 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.

Given the integer n, return the minimum number of cuts needed to divide a circle into n equal slices.

Input & Output

Example 1 — Four Equal Slices
$ Input: n = 4
Output: 4
💡 Note: To divide a circle into 4 equal slices, we need 4 cuts through the center. Each cut creates one slice boundary.
Example 2 — Single Slice
$ Input: n = 1
Output: 0
💡 Note: For 1 slice (the whole circle), no cuts are needed.
Example 3 — Three Equal Slices
$ Input: n = 3
Output: 3
💡 Note: To create 3 equal slices, we need 3 cuts, each at 120° angles from each other through the center.

Constraints

  • 1 ≤ n ≤ 106

Visualization

Tap to expand
Minimum Cuts to Divide a Circle INPUT center Divide into n equal slices n = 4 slices needed Goal: 4 equal parts like a pizza ALGORITHM STEPS 1 Check if n = 1 No cuts needed, return 0 2 Check if n is even Cuts can pass through center 3 Even: return n/2 Each cut makes 2 slices 4 Odd: return n Each cut from edge to center 2 cuts = 4 slices FINAL RESULT 1 2 3 4 Cut 1 Cut 2 Output: 2 OK 4/2 = 2 cuts needed Key Insight: For n=1: No cuts needed (0). For even n: Each diameter cut creates 2 slices, so n/2 cuts suffice. For odd n: Diameter cuts don't work evenly, need n individual radius cuts from center to edge. Formula: n==1 ? 0 : (n%2==0 ? n/2 : n) TutorialsPoint - Minimum Cuts to Divide a Circle | Optimal Solution
Asked in
Google 15 Microsoft 12
23.4K Views
Medium Frequency
~5 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen