Question d’entretien chez Sparx Learning

Find the longest increasing subsequence in an array

Réponse à la question d'entretien

Utilisateur anonyme

12 févr. 2016

A quick C# answer with the info given :) void Main() { int[] test = new int[]{1,2,3,2,2,3,1,2,3,4,5,6,7,8,4,3,2,4,3,8,9,0}; List sequence = new List(); List newLongest = new List(); for (int i = 0; i test[i]) sequence.Add(test[i]); if (test[i + 1] 0) { sequence.Add(test[i]); //Still need the previous one because that was higher than its predecessor. if (sequence.Count() > newLongest.Count()) newLongest = sequence; sequence = new List(); //reset the list } } } } newLongest.Dump(); //Linqpad method to show the array Console.WriteLine(newLongest.Count()); }