Topic notebook / 02

Strings & windows

A moving window represents a contiguous section. Extend it to discover new values and shrink it when a rule is broken.

What to look for

  • Define what makes the window valid.
  • Keep both pointers moving forward.
  • Update the answer only for a valid window.

Work through a question

10 available
01

Find a Clean Signal

A receiver records lowercase letter codes. Return the longest continuous segment with no repeated code, not just its length. If segments tie, return the earliest one.

Medium / Sliding window / interactive
02

Fit a Letter-Budget Banner

A sign maker can stock at most k distinct lowercase letter stamps. Return the longest continuous piece of a message that fits that budget. Repeated letters are allowed. If lengths tie, keep the earliest piece.

Medium / Frequency-count sliding window / interactive
03

Find the Smallest Supply Label

A lowercase label must contain every requested letter, including repeated requests. Return its shortest continuous piece that covers the request. Ties keep the earliest piece; no covering piece returns "".

Hard / Minimum covering window / interactive
04

Find the Longest Mirror Message

Return the longest continuous piece of a lowercase message that reads the same forward and backward. Ties keep the earliest piece.

Medium / Expand around centers / interactive
05

Repaint a Signal Run

A beacon log uses uppercase ASCII letters. Repaint at most k positions so one continuous run has a single letter. Return the largest run length, not the repainted text. Empty logs return 0.

Medium / Frequency sliding window / interactive
06

Compare Letter Inventories

Two lowercase ASCII crate labels are interchangeable when their letter inventories agree, including repeated letters. Given a JSON object with left and right strings, return an explicit boolean.

Easy / Frequency balance / interactive
07

Bundle Rearrangeable Labels

Bundle lowercase ASCII labels with identical letter inventories. Preserve duplicates. Sort each bundle alphabetically, then sort the bundles lexicographically so the returned JSON is deterministic.

Medium / Canonical signature map / interactive
08

Check a Mirror Stamp

A stamp may contain printable ASCII text. Ignore everything except ASCII letters and digits, compare letters without case, and return whether the remaining sequence reads equally in both directions.

Easy / Two pointers with skipping / interactive
09

Count Mirror Fragments

Count every nonempty palindromic slice of a lowercase ASCII message. Different positions count separately even when their text is identical. Return a number, not distinct fragment texts.

Medium / Odd and even center expansion / interactive
10

Pack Labels Without Escaping

Given a JSON list of ASCII strings (including empty strings and # marks), return {"encoded": string, "decoded": list}. Frame each label as decimal character length, #, then exactly that many characters. Decode your own encoding and preserve every label.

Medium / Length-prefixed framing / interactive

Where this leads

Return to the roadmap to try a different kind of problem.