TIP102 Unit 5 Session 1 Standard (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?
What should be the attributes of the Villager
class?
Villager
class should have name
, species
, catchphrase
, and furniture
attributes.How do we instantiate a new Villager
object?
Villager
constructor with the appropriate parameters.What should the default value of the furniture
attribute be?
furniture
attribute should be an empty list.HAPPY CASE
Input:
apollo = Villager("Apollo", "Eagle", "pah")
print(apollo.name)
print(apollo.species)
print(apollo.catchphrase)
print(apollo.furniture)
Output:
"Apollo"
"Eagle"
"pah"
[]
Explanation:
The `Villager` object is instantiated correctly with the given attributes, and the default furniture list is empty.
EDGE CASE
Input:
villager = Villager(", ", ")
print(villager.name)
print(villager.species)
print(villager.catchphrase)
print(villager.furniture)
Output:
"
"
"
[]
Explanation:
Even with empty string attributes, the `Villager` object should be instantiated correctly, and the default furniture list should still be empty.
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 Object-Oriented Programming problems, we want to consider the following approaches:
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Define the Villager
class with the necessary attributes and create an instance of this class.
1) Define the `Villager` class.
2) Implement the constructor to initialize `name`, `species`, `catchphrase`, and `furniture`.
3) Instantiate a `Villager` object with the given attributes.
4) Verify the attributes by printing them out.
⚠️ Common Mistakes
Implement the code to solve the algorithm.
class Villager:
def __init__(self, name, species, catchphrase):
self.name = name
self.species = species
self.catchphrase = catchphrase
self.furniture = []
# Instantiate the Villager class
apollo = Villager("Apollo", "Eagle", "pah")
Review the code by running specific example(s) and recording values (watchlist) of your code's variables along the way.
Villager
object apollo
.apollo.name
, apollo.species
, apollo.catchphrase
, and apollo.furniture
.Evaluate the performance of your algorithm and state any strong/weak or future potential work.
Assume N
represents the number of attributes in the Villager
class.
O(1)
because initializing an object and setting attributes are constant-time operations.O(1)
for each Villager
instance because it uses a fixed amount of memory for its attributes.