Student Branch Filter

Easy
0/40
0 upvote
Asked in company
HCL Technologies

Problem statement

You are given a list of college students. Each student is represented by a set of attributes: a unique integer ID, a string name, and a string branch.


Your task is to write a program that filters this list and creates a new, separate list containing only the students whose branch is exactly "Mechanical".


The students in the returned list should maintain their relative order from the original list.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line contains a single integer N, the total number of students.

The next N lines each contain the details of one student in a comma-separated format: ID,Name,Branch.


Output Format:
For each student in the filtered "Mechanical" list, print their details on a new line in the format: ID: [id], Name: [name], Branch: [branch].

If no students are found in the "Mechanical" branch, print a single line: No students found in the Mechanical branch.


Note:
The branch name matching is case-sensitive. For example, "mechanical" would not be considered a match for "Mechanical".
Sample Input 1:
4
101,John Doe,CSE
102,Jane Smith,Mechanical
103,Peter Jones,EEE
104,Mary Miller,Mechanical


Sample Output 1:
ID: 102, Name: Jane Smith, Branch: Mechanical
ID: 104, Name: Mary Miller, Branch: Mechanical


Explanation for Sample 1:
The program iterates through the four students. It finds that Jane Smith (ID 102) and Mary Miller (ID 104) belong to the "Mechanical" branch and adds them to the new list, preserving their original order.


Sample Input 2:
3
201,Alice,CSE
202,Bob,EEE
203,Charlie,IT


Sample Output 2:
No students found in the Mechanical branch.


Explanation for Sample 2:
None of the students in the input list belong to the "Mechanical" branch, so the program outputs the corresponding message.


Expected Time Complexity:
The expected time complexity is O(N).


Constraints:
0 <= N <= 1000
1 <= ID <= 10^5
1 <= length of Name, Branch <= 50
Student names can contain spaces.
Approaches (1)
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Student Branch Filter
Full screen
Console