Reported September 2026
Capital Onesliding window

Count Good Tuples

Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Capital One OA. Under 2s to a working solution.
Founder's read

Capital One reported this one in September 2026, and it looks easier than it is. You get an integer array and have to count windows of three consecutive values where exactly two match. The opening question is what data structure the solution hinges on, and the honest answer is almost none. A fixed window of size three and a few equality checks do the job. The trap is the "exactly two" wording, which quietly kills the all-equal case. If you blank on that during the OA, StealthCoder is the quiet backup running on your screen.

The problem

You are given an integer array a. A tuple of three consecutive values is good when exactly two of its three values are equal.
For example, (2, 1, 2) is good; (1, 1, 1) and (1, 2, 3) are not. Return the number of good tuples. Tuples may overlap.
A solution no worse than O(a.length²) is accepted.

Function
solution(a: int[]) → int

Examples
Example 1
a = [1,1,1,2,1,3,4]
return = 2
The five triples are (1,1,1), (1,1,2), (1,2,1), (2,1,3), and (1,3,4). Only the second and third have exactly two equal values.

Constraints
0 ≤ a.length ≤ 100000
-1000000000 ≤ a[i] ≤ 1000000000
An array with fewer than three elements contains no tuples of length three.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a sliding window of width 3. For each index i from 0 to n-3, look at x=a[i], y=a[i+1], z=a[i+2]. Count the triple when exactly one pair is equal. Cleanest check: (x==y) + (x==z) + (y==z) equals exactly 1. If all three match, that sum is 3. If none match, it's 0. Two equal values give exactly 1, so you never need a hash map or a counter. The common pitfall is writing x==y or y==z or x==z, which also counts (1,1,1) and fails the first example. Another miss is short arrays. If length is under 3, the loop never runs and you return 0, so don't special-case anything fancy. The stated bound allows O(n squared), but this runs in O(n) time and O(1) space. If you freeze on the equality logic live, StealthCoder is the hedge that surfaces the three-comparison sum so you can type it and move on.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Count Good Tuples cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as count good triplets. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Capital One's OA.

Capital One reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Good Tuples FAQ

How hard is the Count Good Tuples question really?+

Easy. It's a single pass with a window of three. The only real difficulty is reading "exactly two equal" correctly and excluding the all-equal triple. If you code it in one loop with three comparisons, you're done in a few minutes.

What's the trick to counting good tuples?+

Compare the three pairs in each window and sum the booleans. A good tuple has exactly one equal pair. All three equal gives a sum of 3, all different gives 0, and two equal gives 1. Count when the sum is 1.

Do I need a hash map for this?+

No. Tuples are consecutive, so you only ever look at a[i], a[i+1], a[i+2]. A hash map adds nothing. Reaching for one is the usual over-engineering mistake on this problem, and it pushes you toward the slower approach.

What edge cases should I test before submitting?+

Test an empty array, arrays of length 1 and 2, which must return 0, and an all-equal array, which must also return 0. Then run the sample [1,1,1,2,1,3,4] and confirm you get 2. Large values up to a billion don't matter since you only compare.

How should I prepare for this in 48 hours?+

Practice fixed-size sliding window problems and write the loop bounds cleanly, i from 0 to n-3. Spend the rest of your time on the careful reading habit. Underline words like "exactly" and "consecutive" in every prompt, since those words decide the solution.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Capital One.

OA at Capital One?
Invisible during screen share
Get it