Find the Distance Value Between Two Arrays
A easy-tier problem at 70% community acceptance, tagged with Array, Two Pointers, Binary Search. Reported in interviews at Zepto and 0 others.
You're staring at two arrays and a distance threshold. The problem seems straightforward until you realize the brute force scan eats time on a live OA. This shows up at Zepto and similar companies testing your ability to choose the right tool. The trick isn't complex, but picking between a two-pointer scan and binary search separates the candidate who moves fast from the one who second-guesses. The 70% acceptance rate means most people get it, but most also code the slower path first.
Companies that ask "Find the Distance Value Between Two Arrays"
Find the Distance Value Between Two Arrays 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. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.
Get StealthCoderThe distance value counts how many elements from the first array have no 'close neighbor' in the second array, where 'close' means within your distance threshold. The naive approach checks every pair, which works on small inputs but telegraphs inefficiency. Two pointers shine here: sort both arrays, then for each element in the first array, use a pointer to find if any element in the second array falls within the distance window. Binary search is the alternative hedge if two pointers doesn't click in your head. The real gotcha is forgetting to sort first, which kills the pointer approach entirely. If you blank on the pattern mid-OA, StealthCoder surfaces the sorted two-pointer solution in seconds, invisible to the proctor.
Pattern tags
You know the problem.
Make sure you actually pass it.
Find the Distance Value Between Two Arrays recycles across companies for a reason. It's easy-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. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find the Distance Value Between Two Arrays interview FAQ
Do I need to sort both arrays?+
Yes. Without sorting, two pointers won't work because you can't guarantee you'll find the closest element. Sorting is the prerequisite for the efficient approach. Brute force avoids it but costs time.
Is this problem still asked at Zepto and similar companies?+
Yes. The data shows it's in the Zepto interview pool. Companies use it because it tests sorting, iteration strategy, and the ability to pick between two-pointer and brute force quickly.
What's the actual trick that makes this not just a for loop?+
Once both arrays are sorted, you don't reset your pointer in the second array for each new element. Instead, you advance it monotonically, because elements get further apart as you move right. This is the two-pointer pattern that cuts complexity.
How does binary search fit in instead of two pointers?+
For each element in the first array, binary search the second array to find the closest element. If the closest element is within distance, skip it. Binary search is a valid alternative if two pointers doesn't feel natural.
Is an acceptance rate of 70% considered easy difficulty?+
Yes. A 70% acceptance rate on an easy problem confirms most people solve it correctly, but the execution speed and approach choice still matter in a live OA. You need to code the right path, not just any working path.
Want the actual problem statement? View "Find the Distance Value Between Two Arrays" on LeetCode →