Ctrl K

Rotating Candy Shop

Medium
A candy shop has n stands arranged in a circle on a rotating platform. Stand i sells a candy for prices[i], and it starts out holding flavor i. The price belongs to the stand, not to the flavor. For shift_cost you can rotate the candies: the flavor on stand i moves to stand (i + 1) mod n, for all stands at once. You may rotate as many times as you like and buy at any moment between rotations. You need one candy of each of the n flavors. Return the minimum total spend: the prices of the candies you buy plus the cost of every rotation.
Example 1
prices=[9, 2, 8], shift_cost=3 → 12

Buy flavor 1 for 2. Turn (3): flavor 0 moves onto stand 1, buy it for 2. Turn again (3): flavor 2 is now on stand 1, pay 2 once more. Total 2 + 3 + 2 + 3 + 2 = 12, compared with 19 without turning.

Example 2
prices=[4, 5, 6], shift_cost=10 → 15

Turning is too expensive, so just buy everything as is: 4 + 5 + 6 = 15.

Constraints
  • 1 ≤ n = len(prices) ≤ 1000
  • 1 ≤ prices[i] ≤ 10⁹
  • 1 ≤ shift_cost ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Below a Bound MediumLongest Ridge on the Route MediumLatest Clock From Digits MediumStrongest Signal Spot MediumFlanking Move on the Board Medium
loading Python…
Input
prices=[9, 2, 8], shift_cost=3
Expected
12

Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.