Find K'th Character of Decrypted String
You are given an encrypted string where repeated substrings are represented by the substring followed by its count. Your task is to find the K'th character of the decrypted string. The decrypted string is 1-based indexed.
For example, the string "aabbbcdcdcd" can be encrypted as "a2b3cd3".
Input:
The first line contains an encrypted string 'S'.
The second line contains an integer 'K'.
Output:
Output the K'th character of the decrypted string derived from the encrypted string 'S'.
Example:
Input:
S = "a2b3cd1e2"
K = 5
Output:
c
Constraints:
- 2 <= N <= 105
- 1 <= K <= M
- 1 <= M <= 1018
Note:
- Input string consists of lowercase characters only, without spaces.
- If a substring count is 1, it will be followed by the integer '1' (e.g., "aabcdee" -> "a2bcd1e2").
- The frequency can be more than one digit (e.g., "ab12c3").
- The frequency can be in parts (e.g., "aaaabbbb" can be "a2a2b3b1").
- You are not required to print the result; just implement the function logic.
Be the first one to answer
Add answer anonymously...
Top HashedIn by Deloitte Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in HashedIn by Deloitte Software Developer
>
HashedIn by Deloitte Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app