Hone logo
Hone
Problems

Identifying Classes with Excessive Enrollment

Many educational institutions need to monitor class sizes to ensure optimal learning environments. This challenge asks you to analyze a list of classes and identify those that exceed a specified maximum student capacity. Successfully solving this problem is crucial for resource allocation, scheduling adjustments, and maintaining quality education.

Problem Description

You are given a list of classes, where each class is represented as a record (or object, depending on your chosen language) containing two pieces of information: the class name (a string) and the number of students enrolled (an integer). Your task is to write a function that takes this list of classes and a maximum student capacity as input. The function should return a new list containing only the names of the classes that have more students enrolled than the specified maximum capacity.

Key Requirements:

  • The function must accept a list of class records and a maximum capacity integer as input.
  • The function must iterate through the list of classes.
  • For each class, it must compare the number of enrolled students to the maximum capacity.
  • If a class has more students than the maximum capacity, its name should be added to the output list.
  • The function must return a list of class names that exceed the maximum capacity.

Expected Behavior:

The function should accurately identify and return the names of classes that are over-enrolled based on the provided maximum capacity. The order of the class names in the output list does not matter.

Edge Cases to Consider:

  • An empty input list of classes.
  • A maximum capacity of 0.
  • Classes with exactly the maximum number of students (these should not be included in the output).
  • Class names containing spaces or special characters.
  • Negative student counts (treat as invalid and ignore).

Examples

Example 1:

Input: [
  {"class_name": "Math 101", "student_count": 30},
  {"class_name": "History 202", "student_count": 45},
  {"class_name": "English 101", "student_count": 25},
  {"class_name": "Physics 303", "student_count": 50}
]
Maximum Capacity: 35
Output: ["History 202", "Physics 303"]
Explanation: History 202 (45 students) and Physics 303 (50 students) both have more than 35 students. Math 101 (30) and English 101 (25) do not.

Example 2:

Input: [
  {"class_name": "Art 101", "student_count": 10},
  {"class_name": "Music 202", "student_count": 20},
  {"class_name": "Drama 303", "student_count": 35}
]
Maximum Capacity: 25
Output: ["Music 202", "Drama 303"]
Explanation: Music 202 (20 students) and Drama 303 (35 students) exceed the capacity of 25. Art 101 (10) does not.

Example 3:

Input: []
Maximum Capacity: 15
Output: []
Explanation: The input list is empty, so there are no classes to evaluate.

Constraints

  • The input list of classes will contain between 0 and 1000 class records.
  • Each class record will have a class_name (string) and student_count (integer).
  • student_count will be a non-negative integer. Negative values should be ignored.
  • Maximum Capacity will be a non-negative integer.
  • The length of class_name will be between 1 and 50 characters.
  • The solution should have a time complexity of O(n), where n is the number of classes in the input list.

Notes

Consider using a loop to iterate through the list of classes. A simple comparison within the loop will determine if a class should be added to the output list. Remember to handle the edge cases described above to ensure the robustness of your solution. Focus on clarity and readability in your code.

Loading editor...
plaintext