We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
funccountSort(arr[][]string){// Find the maximum value from the first elementsmaxVal:=0for_,v:=rangearr{num,_:=strconv.Atoi(v[0])ifnum>maxVal{maxVal=num}}// Create a slice of slices to hold the countscount:=make([][]string,maxVal+1)// Replace strings in the first half of the array with '-'fori:=rangearr{num,_:=strconv.Atoi(arr[i][0])ifi<len(arr)/2{count[num]=append(count[num],"-")}else{count[num]=append(count[num],arr[i][1])}}// Flatten the count slice and print the sorted stringsfor_,sublist:=rangecount{for_,str:=rangesublist{fmt.Print(str+" ")}}fmt.Println()}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →
Go