Move History

Fork Selected
  • Description

    Suzuki needs help lining up his students!

    Today Suzuki will be interviewing his students to ensure they are progressing in their training. He decided to schedule the interviews based on the length of the students name in descending order. The students will line up and wait for their turn.

    You will be given a string of student names. Sort them and return a list of names in descending order.

    Here is an example input:

    string = 'Tadashi Takahiro Takao Takashi Takayuki Takehiko Takeo Takeshi Takeshi' Here is an example return from your function:

    lst = ['Takehiko', 'Takayuki', 'Takahiro', 'Takeshi', 'Takeshi', 'Takashi', 'Tadashi', 'Takeo', 'Takao'] Names of equal length will be returned in reverse alphabetical order (Z->A) such that:

    string = "xxa xxb xxc xxd xa xb xc xd" Returns

    ['xxd', 'xxc', 'xxb', 'xxa', 'xd', 'xc', 'xb', 'xa']

    Code
    using System;
    using System.Linq;   
    
     public class Kata
        {
            public static string[] LiningUpHisStudents(string s)
            {
                var query = s.Split(' ').OrderByDescending(x => x.Length).ThenByDescending(x => x).ToArray();
                return query;
            }
        }
    Test Cases
    namespace Solution {
      using NUnit.Framework;
      using System;
    
      // TODO: Replace examples and use TDD development by writing your own tests
    
      [TestFixture]
      public class SolutionTest
      {
        [Test]
        public void MyTest()
        {
          string s = "Tadashi Takahiro Takao Takashi Takayuki Takehiko Takeo Takeshi Takeshi";
                string[] S = { "Takehiko", "Takayuki", "Takahiro", "Takeshi", "Takeshi", "Takashi", "Tadashi", "Takeo", "Takao" };
                string[] Test = Kata.LiningUpHisStudents(s);
               CollectionAssert.AreEqual(Kata.LiningUpHisStudents(s), S);
        }
      }
    }