Nth
character in Decrypted String
Every
character in the input string is followed by its frequency. Write a function to
decrypt the string and find the n0' character of the decrypted string. If no
character exists at that position 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.
Input
Specification:
inputl:
a string
input2:
n, the position of the character starting from 1
Output
Specification: Return the character which occurs at the nu' position in the
decrypted string. Return "-1" if no character exists at that
position.
Example
1
Input1=a2b3
Input2=3
Output=b
Code(Python 3)
def
Character(input1,n):
res=""
for i in range(0,len(input1)):
if input1[i].isalpha():
res+=input1[i]*int(input1[i+1])
if(n<=len(res)):
return
res[n]
else:
return
-1
print(Character("a2b3",3))
0 Comments
Post a Comment