Dsa
Two Pointers
Easy
Inventory Price Matcher
You have two sorted lists of prices representing items in Warehouse A and Warehouse B. A price in Warehouse A is 'matchable' if there is at least one price in Warehouse B within a difference of K (inclusive). Count how many unique items (indices) in Warehouse A are matchable.
Input Format:
Line 1: An integer K.
Line 2: Sorted prices for Warehouse A.
Line 3: Sorted prices for Warehouse B.
Output Format:
A single integer representing the count of matchable items in Warehouse A.
Example:
Input:
5
10 20 30
15 25
Output:
3
(Explanation: 10 matches 15 (diff 5), 20 matches 15 or 25 (diff 5), 30 matches 25 (diff 5). All 3 match.)
Key concepts
two_pointerscounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now