Interview Questions/Coding/Shifted Keyboard Recovery

Shifted Keyboard Recovery

Preview mode. Log in to edit, run, submit, and save progress.

Easy

Shifted Keyboard Recovery

A keyboard diagnostic receives a direction L or R and the string that was typed. The keyboard layout sequence is qwertyuiopasdfghjkl;zxcvbnm,./ from left to right. If the direction is R, every typed key is one position to the right of the intended key, so recover the intended key by moving left in the layout. If the direction is L, recover by moving right in the layout. Decode each typed string. Input Format: The first line contains t, the number of test cases. Each test case contains a direction character and a typed string. Output Format: For each test case, print the intended string.

Examples

Example 1
Input:
1
R s;;upimrrfod;pbr
Output:
allyouneedislove

Explanation: The direction R means each typed key is one key to the right of the intended character, so each character is shifted left in the layout.

Approach hint

Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp