
Price changes month to month
easyPrice changes month to month
Zillow Python Interview Question
Zillow's market reports show how a city's median home price changed from one month to the next.
Write a function percent_changes(prices) that takes a list of monthly median prices, oldest first, and returns a list with the percentage change from each month to the next, rounded to 1 decimal place. A list with fewer than two prices has no changes, so return an empty list.
Asked of
- Data Engineer
- Data Scientist
- Analytics Engineer
- ML Engineer
- AI Engineer
Example 1
Input
percent_changes([400000, 420000, 399000])
Output
[5, -5]
Example 2
Input
percent_changes([250000])
Output
[]
Explanation
In the first example, the price rose from 400,000 to 420,000, which is a 5.0% increase, and then fell to 399,000, which is a 5.0% drop. In the second example there is only one month, so there are no changes to report.
Submit also runs 3 hidden test cases that check edge cases.
Company
Zillow
Difficulty
easy
Topic
arrays
Language
Python
Your code
Loading Python in the background. You can start writing.