
Two homes that match a budget
mediumTwo homes that match a budget
Zillow Python Interview Question
Zillow helps investors find two homes whose prices add up to exactly their budget.
Write a function find_pair(prices, budget) that returns the positions of the two different homes whose prices add up to the budget, as a list [i, j] with i smaller than j. There is always exactly one such pair.
Asked of
- Data Engineer
- Data Scientist
- Analytics Engineer
- ML Engineer
- AI Engineer
Example 1
Input
find_pair([350000, 420000, 180000, 270000], 450000)
Output
[2, 3]
Example 2
Input
find_pair([500, 500], 1000)
Output
[0, 1]
Explanation
In the first example, the homes at positions 2 and 3 cost 180,000 and 270,000, which add up to the budget of 450,000. Positions start at 0.
Submit also runs 3 hidden test cases that check edge cases.
Company
Zillow
Difficulty
medium
Topic
hashing
Language
Python
Your code
Loading Python in the background. You can start writing.