Base64 Decoded Length
Easy About 8 min Free, no account needed
The decoded size is pure arithmetic - no need to decode.
The brief
Given a valid base64 string (length a multiple of 4, possibly ending in one or
two = padding characters), return the length in bytes of the decoded
data. An empty string decodes to 0 bytes.
Convert.FromBase64String(...).Length allocates the entire decoded buffer
just to read its length. The hidden test encodes ~150 KB under a 16 KB
allocation budget. Compute the decoded length from the input itself, with zero
allocations.
Starter code
using System;
public class Solution
{
// TODO: return the byte length of the decoded base64 payload.
public int DecodedLength(string b64)
{
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
- Math and number theory
- Replace enumeration with a formula: GCD, modular arithmetic, digit math and closed-form counting.
- 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.
- Excel Column Number Easy Free Spreadsheet columns are base-26 with no zero digit.
- Multiply Numeric Strings Medium Free Schoolbook multiplication of numbers thousands of digits long.
- Maximum Bracket Depth Easy Free How deep do the parentheses nest? A counter beats a stack.