A vintage bank vault has a circular drum engraved with n letters, given as the string s. Turning the drum one notch to the left moves its first letter to the end; turning it one notch to the right moves its last letter to the front. A technician's maintenance ledger lists a sequence of turns that must be replayed in the given order, each entry giving a direction and how many notches to turn. After replaying the entire ledger, report the letters remaining on the drum, read starting from the same fixed reference mark.
s.m, the number of ledger entries.m lines contains two integers direction and amount, where direction = 1 means turn left by amount notches and direction = 0 means turn right by amount notches.A single line containing the drum's letters, in order, after all m ledger entries have been applied.
s consists only of lowercase English letters.Example 1
Input
abc 2 0 1 1 2
Expected
bca
Explanation
Start with "abc". The first entry turns the drum right by 1: the last letter 'c' moves to the front, giving "cab". The second entry turns the drum left by 2: the first letter moves to the end, twice: "cab" -> "abc" -> "bca". The final drum reads "bca".
Example 2
Input
hello 1 1 2
Expected
llohe
Explanation
Start with "hello". The single entry turns the drum left by 2: "hello" -> "elloh" (one left turn) -> "llohe" (a second left turn). The final drum reads "llohe".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →