Java Program to Expand Letters Based on Following Digits in a String- Interview Question asked in Deloitte, Infomerica

The provided Java code snippet expands a compressed string based on the rules defined by the input format. Let's go through the logic step-by-step: Purpose of the Code: The code aims to decode a string where a letter is followed by a digit that specifies how many times the letter should be repeated. For example, given the input string `"d2r3w4t2"`, the output will be `"ddrrrwwwwtt"`. ### Key Components of the Code: 1. **Initialization:** - `str`: The input string to be decoded (`"d2r3w4t2"`). - `StringBuilder sb`: A dynamic string object to build the decoded output. - `char[] ch`: An array of characters from the input string to facilitate character-by-character processing. - `int i`: A loop counter initialized to zero, used to track the current character index. 2. **Main Loop (`for` loop):** - The loop iterates through each character in the `ch` array except the last one (`j - **If the current character `ch[j]` is a ...