Unit 5 Session 1 (Click for link to problem statements)
TIP102 Unit 5 Session 1 Standard (Click for link to problem statements)
TIP102 Unit 5 Session 1 Advanced (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Established a set (2-3) of test cases to verify their own solution later.
- Established a set (1-2) of edge cases to verify their solution handles complexities.
- Have fully understood the problem and have no clarifying questions.
- Have you verified any Time/Space Constraints for this problem?
print_results()
to display the race results in order, with each player's position in the race.HAPPY CASE
Input: race_results = [Player("Peach", "Daytripper"), Player("Mario", "Standard Kart M"), Player("Luigi", "Super Blooper")]
Output:
1. Peach
2. Mario
3. Luigi
Explanation: The function correctly enumerates through the list and prints each player's character in order of their race position.
EDGE CASE
Input: race_results = []
Output:
Explanation: The function should handle an empty list without errors and not print any results.
Match what this problem looks like to known categories of problems, e.g. Linked List or Dynamic Programming, and strategies or patterns in those categories.
For list enumeration problems, we want to consider the following approaches:
enumerate()
to loop through the list with an index.Plan the solution with appropriate visualizations and pseudocode.
General Idea: Loop through the race_results
list and print each player's position along with their character name.
1) Create a function `print_results(race_results)`.
2) Loop through `race_results` using `enumerate()` to get both the index (starting at 1) and the `Player` object.
3) Print each player's position in the format "<place>. <character>".
⚠️ Common Mistakes
enumerate()
index at 1.Implement the code to solve the algorithm.
def print_results(race_results):
for place, racer in enumerate(race_results, start=1):
print(f"{place}. {racer.character}")
Review the code by running specific example(s) and recording values (watchlist) of your code's variables along the way.
Evaluate the performance of your algorithm and state any strong/weak or future potential work.