Skip to content

Pooh's To Do's

Raymond Chen edited this page Aug 1, 2024 · 4 revisions

TIP102 Unit 1 Session 1 Standard (Click for link to problem statements)

Problem Highlights

  • 💡 Difficulty: Easy
  • Time to complete: 5 mins
  • 🛠️ Topics: Functions, Strings, Conditionals

1: U-nderstand

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?
  • The function print_todo_list() should take a list of strings tasks and print each task on a new line, prefixed with its position in the list.
HAPPY CASE
Input: ["Count all the bees in the hive", "Chase all the clouds from the sky", "Think", "Stoutness Exercises"]
Expected Output: 
Pooh's To Dos:
1. Count all the bees in the hive
2. Chase all the clouds from the sky
3. Think
4. Stoutness Exercises


EDGE CASE
Input: []
Expected Output:
Pooh's To Dos:

2: M-atch

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.

This problem falls under: List Iteration and Formatting Output.

3: P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Define a function that prints each task with its corresponding number in the list.

1. Define the function `print_todo_list(tasks)`.
2. Print the header "Pooh's To Dos:".
3. Iterate over the range of indices from 1 to len(tasks).
4. Print each task in the format "i. task" where `i` is the current index.

⚠️ Common Mistakes

  • Forgetting to adjust the index when printing tasks.

4: I-mplement

Implement the code to solve the algorithm.

def print_todo_list(tasks):
    # Print the header
    print("Pooh's To Dos:")
    
    # Iterate over the range of indices from 1 to len(tasks)
    for i in range(1, len(tasks) + 1):
        # Print each task in the specified format
        print(f"{i}. {tasks[i - 1]}")

5: R-eview

Review the code by running specific example(s) and recording values (watchlist) of your code's variables along the way.

Call the function with the provided examples:

print_todo_list(["Count all the bees in the hive", "Chase all the clouds from the sky", "Think", "Stoutness Exercises"])
print_todo_list([])

Expected outputs:

Pooh's To Dos:
1. Count all the bees in the hive
2. Chase all the clouds from the sky
3. Think
4. Stoutness Exercises

6: E-valuate

Evaluate the performance of your algorithm and state any strong/weak or future potential work.

  • Time Complexity: O(n) where n is the number of elements in the list since we need to iterate through all elements.
  • Space Complexity: O(1) as no additional data structures are used beyond the iteration variable.
Clone this wiki locally