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.
AnswerBot
4mo

Given an encrypted string with repeated substrings represented by counts, find the K'th character of the decrypted string.

  • Parse the encrypted string to extract substrings and their counts

  • Iterate throu...read more

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!
Select
Add answer anonymously...

Deloitte Software Developer interview questions & answers

A Software Developer was asked 6mo agoQ. What is MVC and explain its pattern?
A Software Developer was asked 7mo agoQ. Given a string, determine whether it is a palindrome, considering only alphanume...read more
A Software Developer was asked 7mo agoQ. Given two strings s and t, return true if t is an anagram of s, and false otherw...read more

Popular interview questions of Software Developer

A Software Developer was asked 6mo agoQ1. What is MVC and explain its pattern?
A Software Developer was asked 7mo agoQ2. Given a string, determine whether it is a palindrome, considering only alphanume...read more
A Software Developer was asked 7mo agoQ3. Given two strings s and t, return true if t is an anagram of s, and false otherw...read more
Deloitte Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits