Skip to content
Search lessons, topics, tests…
Esc

    ↑ ↓ moveEnter openEsc close

    Coding problem

    Join numbers into the largest number

    MediumAbout 25 minFull AccessLearn it: Sorting and Selection in C#: Merge Sort, Quickselect, Counting Sort and Custom Comparers

    The task

    A puzzle game deals number tiles, and the player wins by laying them in a row so that reading the row gives the largest number. The server checks each answer against the best one.

    Complete LargestJoin(int[] values). The values are 0 or more. Put them in the order that makes writing them one after another give the largest possible number, and return that number as a string. The result has no leading zeros: when the largest number is zero, return "0". The array is never null and holds at least one value.

    Signature

    public static string LargestJoin(int[] values)

    Examples

    • [40, 5] → "540". 5 then 40 gives 540, which is larger than 405.
    • [0, 0] → "0". "00" is written as "0".

    Limits: Up to 100,000 values; a value can be any int from 0 to int.MaxValue.

    The tests check: one value, zeros, a shorter number going first, numbers that share their first digits, a number that is a prefix of another, int.MaxValue, and 13 values 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 static class Solution
      {
          // Orders the values so that writing them one after another gives the largest number.
          public static string LargestJoin(int[] values)
          {
              throw new NotImplementedException();
          }
      }

      This problem comes with TechInterviewNotes Full Access

      Unlock all paid content on TechInterviewNotes.