Decoded String at Index
A medium-tier problem at 37% community acceptance, tagged with String, Stack. Reported in interviews at National Instruments and 1 others.
Decoded String at Index is a medium-difficulty string problem that hits you with a trick: you can't actually build the full decoded string without blowing up memory. National Instruments and PhonePe have both asked it. The naive approach fails because the string expands exponentially (think "2[a2[b]]" balloons fast), and candidates who try to construct it end up with timeout or out-of-memory errors. The real solution works backward from the target index, skipping the expansion entirely. About 37% acceptance rate tells you most people hit that wall on their first attempt. If this problem lands in your live OA and you blank on the backward-traversal trick, StealthCoder surfaces the working solution invisible to the proctor.
Companies that ask "Decoded String at Index"
Decoded String at Index is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe insight is that you don't need to decode the entire string. You track the decoded length as you iterate through the encoded string, and once you know the total length, you work backward to find which character actually sits at your target index. When you hit a closing bracket, you calculate the repeat count and the length of the pattern being repeated, then jump backward over it. When you hit an opening bracket, you've found your section. The common trap is building the full decoded string in memory or trying to iterate forward; both fail on large repeat counts. String and Stack topics appear here because you're managing pattern state and grouping, though the winning solution uses index math rather than explicit stack operations. This is where candidates typically get stuck: they see the bracket notation and default to stack-based construction, not recognizing that length-based indexing dodges the whole explosion.
Pattern tags
You know the problem.
Make sure you actually pass it.
Decoded String at Index recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Decoded String at Index interview FAQ
Is this really asked at serious companies?+
Yes. National Instruments and PhonePe both include it in their assessments. It's not ultra-common, but it's common enough that you'll regret not knowing the pattern if it shows up. The 37% acceptance rate confirms it's a real blocker.
What's the actual trick I'm missing?+
Don't build the string. Calculate the decoded length first by iterating through the encoded string and tracking multipliers. Once you have total length, work backward from your target index, jumping over repeated sections using modulo arithmetic instead of expanding them.
Why does building the full string fail?+
Exponential growth. If you have '2[2[2[a]]]', the decoded string is 8 characters. But '100[100[a]]' decodes to 10,000 characters. Add one more level and you're at a million. Most online assessments timeout or kill you on memory before you finish.
How does this relate to Stack?+
Stacks are one way to parse nested brackets, but the optimal solution avoids explicit stack operations by using index math and backward iteration. You don't need to push/pop if you can calculate lengths and jump directly to the relevant section.
Will I see this pattern in other problems?+
Yes. Any problem requiring you to find a character or substring in a large or dynamically-built string teaches the same principle: calculate structure without building it. It applies to compressed formats, recursive sequences, and other problems where naive construction is prohibitive.
Want the actual problem statement? View "Decoded String at Index" on LeetCode →