Amazon Online Assessment 2021 (OA) - Simple Cipher

As part of an interesting team exercise, a new group member has developed a straightforward letter-based coding system; everyone on the team is invited to give it a try. This code system is grounded on a wheel of the alphabet that contains upper-case English letters from 'A' to 'Z'. Here's the challenge: there's an encrypted string given to each participant. This scrambled string is composed only of English letters, from 'A' to 'Z'. The team exercise requires that this string be decoded by swapping each letter with the kth letter away on the wheel, moving in a counter-clockwise direction. If you're wondering, counter-clockwise is the opposite direction from how the hands on a clock usually move.

Relevant Amazon OA Problems:

Input

  • encryped: a string
  • k: an integer

Output

the decrypted string

Examples

Example 1:

Input:

1encryped = VTAOG
2k = 2

Output: TRYME

Explanation:

Looking back 2 from 'V' returns 'T', from 'T' returns 'R' and so on. The decrypted string is 'TRYME'.

Try it yourself

Solution

โ†
โ†‘TA ๐Ÿ‘จโ€๐Ÿซ