BackmediumStrings Infosys

Galactic Transmission Decoding Solution

Problem Statement

Given a transmission string and a decoding dictionary, replace all occurrences of alien codes with their corresponding Earth language values in the dictionary, if the code exists in the dictionary, otherwise leave it unchanged.

Example 1
Input
hellohellofoofooxy
Output
hellohellofoofooxyz

Explanation: Step-by-step: 1. Split the input string into substrings of length 2: ['he', 'll', 'o', 'h', 'el', 'lo', 'fo', 'oo', 'xy']. 2. For each substring, check if it exists in the decoding dictionary. If it does, replace it with its corresponding Earth language value. If it doesn't, leave it unchanged. 3. Join the resulting substrings back into a single string to get the output.

Example 2
Input
foobarfoobarxy
Output
foobarfoobarxy

Explanation: Step-by-step: 1. Split the input string into substrings of length 2: ['fo', 'ba', 'ra', 'bo', 'ar', 'xy']. 2. For each substring, check if it exists in the decoding dictionary. If it does, replace it with its corresponding Earth language value. If it doesn't, leave it unchanged. 3. Join the resulting substrings back into a single string to get the output.

Constraints

  • 1 <= length of transmission string <= 1000
  • 1 <= number of key-value pairs in decoding dictionary <= 100
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free