← All problemsSign in

Best Friend Forever

We are going to take a photo of N students in a line. We want to take the best photo. A photo is considered to be the best when the maximum number of students are satisfied. A student is satisfied if he is the right neighbor of his best friend. Each student has only one best friend. You have to find the number of satisfied students in the best photo and the number of different best photos. Print t

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