june cook off

can anybody tell me what is the expected result of “ADACRA” in case when i give string “DUDUD” and how?

The answer in this case will be 2.
It will take 2 flips to make all crayons point to the same direction, i.e downwards.

In this problem, all you have to do is count the number of consecutive appearances of U and D separately.
The answer will be minimum of those two.

My accepted solution.

In DUDUD, the number of segments of ‘U’ is less than number of segments of ‘D’. Therefore if we change U (In 2 steps) , the resulting string becomes DDDDD.

1 Like

2 Flips. Flip both the Us one by one. All it asked to do was to count if U has minimum consecutive blocks, or D

Here is my code for reference- https://www.codechef.com/viewsolution/14276951

1 Like

You can simply store the no of transition from U to D or D to U. and then can calculate the required answer easily.