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?
artists
and set_times
, both of equal length n
.Q: What are the outputs?
artists
list is mapped to their corresponding set time from the set_times
list.Q: Can the lists be empty?
Q: Is the order of elements important?
artists[i]
corresponds to set_times[i]
.Plan the solution with appropriate visualizations and pseudocode.
General Idea: Create a dictionary by iterating over the lists and mapping each artist to their set time.
1) Initialize an empty dictionary `schedule`.
2) Iterate over the range of the length of the `artists` list.
- For each index `i`, set `schedule[artists[i]]` to `set_times[i]`.
3) Return the dictionary `schedule`.
⚠️ Common Mistakes
artists
and set_times
are equal.def lineup(artists, set_times):
schedule = {}
for i in range(len(artists)):
schedule[artists[i]] = set_times[i]
return schedule