Run-Length Decoded Length
Easy About 8 min Free, no account needed
How long would the decoded string be? Do not decode it to find out.
The brief
Given a run-length encoding, letters each followed by a positive count, like
"a12b3", return the length of the decoded string.
Actually expanding the runs materializes the decoded string just to read its
.Length, the hidden encoding decodes to ~10 million characters under a
16 KB allocation budget. You will need to compute the length without ever
building the decoded string.
Starter code
using System;
public class Solution
{
// TODO: return the length of the decoded string for a run-length encoding like "a12b3".
public long DecodedLength(string rle)
{
throw new NotImplementedException();
}
}How it is graded
Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.
What it practices
- String processing
- Parse, scan and match text character by character with correct edge cases.
Related katas
- Add Binary Strings Easy Free Add two binary numbers far too long for any built-in integer.
- Maximum Bracket Depth Easy Free How deep do the parentheses nest? A counter beats a stack.
- Base64 Decoded Length Easy Free The decoded size is pure arithmetic - no need to decode.
- Count Distinct Letters Easy Free How many different letters appear? A 26-slot array already knows.