Program

Problem Statement – Every character in the input string is followed by its frequency.
Write a function to decrypt the string and find the nth character of the decrypted string. If no character exists at that positionthen then return “-1”.
For eg:- If the input string is “a2b3” the decrypted string is “aabbb”.
Note: The frequency of encrypted string cannot be greater than a single digit i.e.<10.

Explanation:

The decrypted string is “abccc”, hence the 5th character in the decrypted string is “c”.

Input : Input Specification:
Input1: A string.
Input2:5

Code

def decrypt(s):
    output = []
    for i in s:
        if(i.isalpha()):
            output.append(i)
        else:
            for _ in range(int(i)-1):
                output.append(output[-1])

    return ''.join(output)

decrypt("a2b3"#'aabbb'

Illuminate Minds Preparations With Test

Subscribe for More Great Articles!

Get Access To Our Premium Courses
Install our application from PlayStore and get discounts on our new courses.

Pin It on Pinterest