Pixel · Easy CodeFree
Missing His Floor
Boo has finally rented an apartment, but he can only walk through walls, not ceilings. Unfortunately, the elevator buttons are possessed: sometimes up means down. Find the first moment the elevator reaches his floor.
Find the number of the first command after which the elevator is on Boo's floor. If Boo lives on floor 0, the answer is 0. If the elevator never gets there, the answer is -1.
The number must be exactly right.
F, the floor where Boo lives. Floors above the ground floor are positive, basements are negative.S, the commands Boo presses, in order: a string of the letters U, D and ! with no spaces.F. Commands are numbered from 1, and ! is a command too. If F = 0, print 0. If the elevator never reaches floor F, print -1.F ≤ 200 000S ≤ 200 0003 UU!DD
4
Sign in to play. It is free.
Sign in