Coding problem
Students in each course
The task
The school office prints a roll for every course: the names of the students who take it.
Complete Rolls(List<Course> courses, List<Student> students, List<Enrolment> enrolments). Course is a record with a Code and a Title; Student is a record with an Id and a Name; an Enrolment links a StudentId to a CourseCode, and it is the only link between students and courses. Return one CourseRoll for every course, in the order of the course list, with the course's Title and the names of its students sorted in ascending ordinal order, which compares characters by their numeric values. A course nobody takes gets an empty list. A student enrolled in the same course more than once appears once, but two different students who share a name both appear. An enrolment whose student or course is not in the lists is ignored. The lists and their items are never null, and student ids and course codes are unique.
Signature
public record Course(string Code, string Title); public record Student(int Id, string Name); public record Enrolment(int StudentId, string CourseCode); public record CourseRoll(string Course, List<string> Students); public static List<CourseRoll> Rolls(List<Course> courses, List<Student> students, List<Enrolment> enrolments)
Examples
courses [("C1", "algebra"), ("C2", "biology")], students [(1, "zoe"), (2, "amy")], enrolments [(1, "C1"), (2, "C1")]→[("algebra", ["amy", "zoe"]), ("biology", [])]. Both students take algebra; nobody takes biology yet.courses [("C1", "algebra")], students [(1, "zoe")], enrolments [(1, "C1"), (1, "C1"), (7, "C1")]→[("algebra", ["zoe"])]. zoe's repeated enrolment counts once, and student 7 is not in the list.
Limits: Up to 20,000 courses, 200,000 students and 600,000 enrolments.
The tests check: no courses, a course with nobody, repeated enrolments, unknown students and courses, two students with the same name, a student on two courses, courses in their list order, names A to Z, and 600,000 enrolments in time.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public record Course(string Code, string Title);
public record Student(int Id, string Name);
public record Enrolment(int StudentId, string CourseCode);
public record CourseRoll(string Course, List<string> Students);
public static class Solution
{
// Every course in list order with its students' names A to Z, through the enrolment list.
public static List<CourseRoll> Rolls(List<Course> courses, List<Student> students, List<Enrolment> enrolments)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.