Asked inMicrosoft Corporation,SWE Intern

Find K’th Character of Decrypted String

You are given an encrypted string where repetitions of substrings are expressed as the substring followed by the count of these substrings. The task is to find the 'K'th character in the decrypted string. The decrypted string uses 1-based indexing.

Example:
The string "aabbbcdcdcd" is encrypted as "a2b3cd3".

Input:

S: The encrypted string.
K: An integer representing the position in the decrypted string you need to find.

Output:

The character at the 'K'th position of the decrypted string obtained from string 'S'.

Example:

Input:
S = "a2b3cd3", K = 5
Output:
'b'

Constraints:

  • 2 <= N <= 105
  • 1 <= K <= M
  • 1 <= M <= 1018

Where 'N' is the length of the encrypted string 'S', and 'M' is the length of the decrypted string from 'S'. All characters in string 'S' are lowercase English letters.

Note: You only need to implement the function as output has been handled. Also, the string will not contain any spaces, and each substring is followed by an integer indicating its frequency.

Be the first one to answer
Add answer anonymously...
Microsoft Corporation SWE Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter