Answers for "Big sorting hackerrank solution in C#"

C#
0

Big sorting hackerrank solution in C#

int n = Convert.ToInt32(Console.ReadLine());
string[] a = new string[n];
for (int i = 0; i < n; i++) 
    a[i] = Console.ReadLine();

Array.Sort(a, (left, right) => {
    if (left.Length != right.Length)
        return left.Length - right.Length;
    else
        return string.CompareOrdinal(left, right); // left.CompareTo(right) is too slow
});
for (int i = 0; i < n; i++) 
    Console.WriteLine(a[i]);
Posted by: Guest on October-18-2021

Code answers related to "Big sorting hackerrank solution in C#"

C# Answers by Framework

Browse Popular Code Answers by Language