Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Q: What is the problem asking for?
Q: What are the inputs?
oxygen_levels
mapping room names to current oxygen levels, and two integers min_val
and max_val
specifying the acceptable range of oxygen levels.Q: What are the outputs?
min_val
and max_val
.Q: Are there any constraints on the values in the dictionary or the range?
min_val
and max_val
define the inclusive range.Plan the solution with appropriate visualizations and pseudocode.
General Idea: Iterate through the dictionary and check if the oxygen levels in each room fall outside the specified range.
1. Initialize an empty list `out_of_range_rooms`.
2. Iterate through the items in the `oxygen_levels` dictionary.
- For each room and its oxygen level:
- Check if the level is less than `min_val` or greater than `max_val`.
- If true, append the room name to `out_of_range_rooms`.
3. Return the list `out_of_range_rooms`.
def check_oxygen_levels(oxygen_levels, min_val, max_val):
out_of_range_rooms = []
for room, level in oxygen_levels.items():
if level < min_val or level > max_val:
out_of_range_rooms.append(room)
return out_of_range_rooms