Chewy | 1st round- Screening(zoom) | 45min

Anonymous User
209
May 13, 2024
May 13, 2024

There were two questions
1. Leetcode Medium
A variation of Top K elements in a list
2. OO Design question
Implement a Product class and an exception class that represent a warehouse that can house a limited number of products. After the limit is reached, if there is an attempt to add an additional product instance, it throws a custom error.
Create two classes.
T. Product

  1. init (self, name) - initialize the instance variable with its name attribute:
  2. _del (self) delete the instance.
  3. Track the number of Product instances.
  4. The number of allowed products can be changed dynamically. It is retrieved by calling Limit get_limit.
    1: If the number of Product instances is less than the current limit, create a new product instance.
  5. Otherwise, throw a UserLimitExceeded exception with the message "Product {name) cannot be created. Maximum {limit) products allowed". Do not create a new instance
  6. UserLimitExceeded(Exception) - This is an exception class. It accepts an error message in its constructor and throws an exception.
    The Limit class and its operations are implemented in the template. Please read the code to understand the application.
    Function Description
    Complete the classes Product and UserLimitExceeded in the editor below.
    Instructions are handled by the boilerplate code.
    Constraints
    • The maximum number of instructions is 100.
    • The maximum number of products is 50.
    • The limit will never be changed to less than the current number of Product instances.
Comments (3)