Problem Brief
Encode or Decode Message
OA
Encodes or decodes a message using a shared numeric key.
Input
- Operation:
- 1 = Encode
- 2 = Decode
- Message (string)
- Key (positive integer)
Encoding (Operation 1)
Duplicates each character based on the corresponding digit in the key.
Example:
Message: Open, Key: 123 → Output: Oppeen
Decoding (Operation 2)
Compresses repeated characters based on digits in the key.
Example:
Message: Oppeen, Key: 123 → Output: Open
Rules
1Example 1
Input
operation = 1, message = "Open", key = 123
Output
"Oppeen"
Explanation
~~
2Example 2
Input
operation = 2, message = "Oppeen", key = 123
Output
"Open"
Explanation
~~~