Skip to content
Search lessons, topics, tests…
Esc

    ↑ ↓ moveEnter openEsc close

    Coding problem

    Race results, with non-finishers last

    EasyAbout 15 minFreeLearn it: LINQ Edge Cases Interviewers Test: Empty Input, Nulls, Overflow, Duplicates and Ties

    The task

    The results board lists the runners who finished, fastest first, and then the runners who did not finish.

    Complete Results(List<Runner> runners). Runner is a record with a Bib number, a Name and the Seconds the runner took, which is null for a runner who did not finish. Return the bib numbers in result order. Every runner with a time comes before every runner without one. The runners with a time are sorted from the fewest seconds up, and equal times by Bib, smallest first. The runners without a time follow, sorted by Bib. Do not change the input list. An empty list gives an empty list. The list and its runners are never null, bib numbers are unique, and times are from 1 to 1,000,000 seconds.

    Signature

    public record Runner(int Bib, string Name, int? Seconds);
    public static List<int> Results(List<Runner> runners)

    Examples

    • [(7, "amy", 3605), (3, "ben", null), (5, "cara", 3490)] → [5, 7, 3]. cara was the fastest; ben did not finish, so he comes last.
    • [(9, "dev", 3600), (2, "eli", 3600), (4, "fay", null), (1, "gus", null)] → [2, 9, 1, 4]. dev and eli tie, so the smaller bib goes first; the two who did not finish follow by bib.

    Limits: Up to 200,000 runners.

    The tests check: an empty list, nobody finishing, everybody finishing, the fastest first, equal times by bib, a non-finisher with a small bib still last, a slow finisher before any non-finisher, that the input list is not changed, and 200,000 runners in time.

    Hints

      The solution opens by itself when all tests pass. You remember more if you try first.

      Sign in to see the solution

      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 Runner(int Bib, string Name, int? Seconds);
      
      public static class Solution
      {
          // Bib numbers in result order: finishers by time then bib, then the non-finishers by bib.
          public static List<int> Results(List<Runner> runners)
          {
              throw new NotImplementedException();
          }
      }

      Sign in to run and submit your code. It stays here while you do.