Count Triples with Matching Letter Sets on Both Sides

Asked at Google · Coding Questions · Difficulty: Hard · Last asked Nov 7, 2026

Given a string of lowercase letters, cut out two neighbouring pieces: a first piece that ends at some position, and a second piece that starts right after it. Count the ways to choose the two pieces so that they use exactly the same set of distinct letters, ignoring how often each letter occurs and in which order.

Loading the problem…