Skip to content
Katabench
Try free

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.

The allocation budget

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

C#
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.

C# coding challenges →

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