Skip to content
Search lessons, topics, tests…
Esc

    ↑ ↓ moveEnter openEsc close

    Coding problem

    Students in each grade band

    MediumAbout 25 minFull AccessLearn it: Hashing Operators: GroupBy, ToLookup, ToDictionary, CountBy and AggregateBy

    The task

    The exam summary shows how many students landed in each grade band, and it always lists all six bands.

    Complete Bands(List<Student> students). Student is a record with a Name and a Mark from 0 to 100. The bands are: A for 90 to 100, B for 80 to 89, C for 70 to 79, D for 60 to 69, E for 50 to 59 and F below 50. Return six BandCount rows, for the bands A, B, C, D, E and F in that order, each with the number of students in that band; a band with nobody in it has 0. The list and its students are never null.

    Signature

    public record Student(string Name, int Mark);
    public record BandCount(char Band, int Students);
    public static List<BandCount> Bands(List<Student> students)

    Examples

    • [("amy", 95), ("ben", 72), ("cara", 90), ("dev", 30)] → [('A', 2), ('B', 0), ('C', 1), ('D', 0), ('E', 0), ('F', 1)]. 95 and 90 are both an A; the bands with nobody still appear, with 0.
    • [] → [('A', 0), ('B', 0), ('C', 0), ('D', 0), ('E', 0), ('F', 0)]. There are no students, but every band is listed.

    Limits: Up to 500,000 students.

    The tests check: an empty list, the edges of every band, marks of 100 and 0, bands with nobody, the bands always in the order A to F, and 500,000 students in time.

    Hints

      Your code

      C#Solution.csLoading the editor…

      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 Student(string Name, int Mark);
      public record BandCount(char Band, int Students);
      
      public static class Solution
      {
          // The number of students in each band, A to F, bands with nobody included.
          public static List<BandCount> Bands(List<Student> students)
          {
              throw new NotImplementedException();
          }
      }

      This problem comes with TechInterviewNotes Full Access

      Unlock all paid content on TechInterviewNotes.