The Full Counting Sort

  • + 0 comments

    I've been struggling a lot to get the Test number 5 to run within time limits. Here is my approach in C# - hope it helps someone.

        public static void countSort(List<List<string>> arr){
            var buckets = new List<string>[100];
            for(int i=0; i<100; i++){
                buckets[i] = new List<string>();
            }
            
            var count = arr.Count();
            var half = count / 2;
            
            for(int i=0; i<count; i++){
                var index = int.Parse(arr[i][0]);
                var value = arr[i][1];
                if(i<half){
                    value = "-";    
                }
                buckets[index].Add(value);
            }
                  
            for(int i=0; i<100; i++){
                var size = buckets[i].Count();
                if (size > 0){
                    Console.Write(string.Join(" ", buckets[i]) + " ");
                }
            }
        }