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.
Charan Singh
1y
function findKthElement(encryptedStr , k){ let decryptedStr = '' let i = 0 //Decrypting the String while(i < encryptedStr.length){ let currentChar = '' let count= '' while(i < encryptedStr.length && i...read more
Help your peers!
Add answer anonymously...
Top Deloitte Software Developer interview questions & answers
Popular interview questions of Software Developer
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