HARDasked at 1 company

Count Pairs With XOR in a Range

A hard-tier problem at 46% community acceptance, tagged with Array, Bit Manipulation, Trie. Reported in interviews at Vimeo and 0 others.

Founder's read

You're staring at an array and need to count pairs whose XOR falls within a given range. It's a hard problem with a 45% acceptance rate, which means half the engineers who see it in their assessment blank or time out. Vimeo has asked this. The trap is thinking you can brute force it or use a simple hash map. You can't. The real solution lives at the intersection of Trie and bit manipulation, and if that pattern hasn't clicked for you yet, StealthCoder surfaces a working solution invisible to the proctor the moment you hit this on the clock.

Companies asking
1
Difficulty
HARD
Acceptance
46%

Companies that ask "Count Pairs With XOR in a Range"

If this hits your live OA

Count Pairs With XOR in a Range is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The core insight: you can't just iterate pairs and check the range. You need a Trie that stores binary representations of numbers, then for each number, traverse the Trie bit by bit to count XOR results that land in your target range. The Trie lets you prune branches that can't possibly fit the range, turning what looks like an O(n squared) disaster into something manageable. Most candidates either try to hash pairs (too slow) or attempt a naive bitwise scan that forgets how to handle the range constraint. The trick is realizing XOR is a path-counting problem on a binary tree, not an arithmetic problem. When the range and array size collide on your assessment and you haven't drilled this exact pattern, StealthCoder runs invisibly during screen share and hands you the Trie-based approach working.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Count Pairs With XOR in a Range recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Pairs With XOR in a Range interview FAQ

Is this actually asked at real companies or just LeetCode?+

Vimeo has reported asking it. At 45% acceptance, it's hard enough that most candidates who encounter it haven't seen the Trie + bit manipulation trick before. It's not common, but it's real.

What's the actual trick I'm missing if brute force fails?+

Stop counting pairs in the array. Start counting XOR values using a Trie of binary representations. For each number, walk the Trie bit by bit to count how many other numbers produce an XOR result within your range. That's where the speedup lives.

How does Trie fit into this when I've only used Trie for strings?+

Treat each number's binary representation as a string of 0s and 1s. Build a Trie where each path from root to leaf represents a number. Then traverse it intelligently based on your XOR range bounds. It's the same data structure, different domain.

Can I solve this with just bit manipulation and no Trie?+

Not efficiently. Bit manipulation alone doesn't help you count pairs fast. The Trie is what allows you to prune the search space as you traverse. Without it, you're back to checking too many pairs.

How hard is this compared to typical hard array problems?+

It's in the upper tier. You need comfort with both Trie construction and bit-level XOR logic, plus the mental jump that XOR queries become path counts on a binary tree. That combination isn't standard preparation.

Want the actual problem statement? View "Count Pairs With XOR in a Range" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.