← All problemsSign in

Precious Stones

Nemo went to the shop to buy a chain for his girlfriend. The shopkeeper has shown him a chain made of some expensive stones. The chain has **n** stones marked from **0** to **n-1**. The **ith** stone is connected with **((i+1)%n)th** stone for each **0 ≤ i th** stone is Ruby, Nemo will exchange it with Amber and vice-versa. He wants to do it in such a way that the value **B** is as small as possib

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start