Identifying Classes with Overcapacity
This challenge focuses on data manipulation and filtering, a fundamental skill in programming. You'll be tasked with analyzing student enrollment data to identify which classes have more than a specified capacity, which is crucial for resource allocation and managing class sizes.
Problem Description
You are given a list of classes, and for each class, you are provided with a list of students enrolled in it. Your task is to return a list of the names of all classes that have more than 5 students enrolled.
- Input: A data structure representing classes and their enrolled students. This can be thought of as a collection of
Classobjects, where eachClassobject has aname(string) and a list ofstudents(each student can be represented by a string name, or a simple identifier). - Output: A list of strings, where each string is the name of a class that has more than 5 students.
- Expected Behavior: Iterate through all provided classes. For each class, count the number of enrolled students. If the count is strictly greater than 5, add the class's name to the result list.
- Edge Cases:
- A class with exactly 5 students should not be included in the output.
- A class with 0 students should not be included.
- An empty input list of classes should result in an empty output list.
Examples
Example 1:
Input: [
{ name: "Introduction to Programming", students: ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] },
{ name: "Data Structures", students: ["Grace", "Heidi", "Ivy"] },
{ name: "Algorithms", students: ["Jack", "Kate", "Liam", "Mia", "Noah", "Olivia", "Peter"] }
]
Output: ["Introduction to Programming", "Algorithms"]
Explanation: "Introduction to Programming" has 6 students, and "Algorithms" has 7 students, both exceeding the limit of 5. "Data Structures" has only 3 students.
Example 2:
Input: [
{ name: "Linear Algebra", students: ["Quinn", "Riley", "Sophia"] },
{ name: "Calculus I", students: ["Thomas", "Ursula", "Victor", "Wendy", "Xavier"] }
]
Output: []
Explanation: Both "Linear Algebra" (3 students) and "Calculus I" (5 students) do not have *more than* 5 students.
Example 3:
Input: []
Output: []
Explanation: An empty input list of classes results in an empty output list.
Constraints
- The number of classes will be between 0 and 1000.
- The number of students in any given class will be between 0 and 50.
- Class names and student names will be alphanumeric strings.
- The solution should be reasonably efficient, aiming for a time complexity that scales well with the number of classes and students.
Notes
- Consider how you will represent the input data. A list of dictionaries or objects, where each dictionary/object represents a class, is a common and effective approach.
- The core logic involves iterating and conditional checking. Think about how to access the student list for each class and determine its size.
- You do not need to worry about duplicate class names or student names for this problem.