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.
Golang
You can not pass the tests.
Do replace main function loop and write logic directly.
packagemainimport("bufio""fmt""io""os""strconv""strings")/* * Complete the 'countSort' function below. * * The function accepts 2D_STRING_ARRAY arr as parameter. */funcmain(){reader:=bufio.NewReaderSize(os.Stdin,16*1024*1024)nTemp,_:=strconv.ParseInt(strings.TrimSpace(readLine(reader)),10,64)n:=int32(nTemp)ans:=make([]string,n)mid:=int((n-1)/2)idx:=int64(0)v:=""fori:=0;i<int(n);i++{arrRowTemp:=strings.Split(strings.TrimRight(readLine(reader)," \t\r\n")," ")pos:=arrRowTemp[0]val:=arrRowTemp[1]idx,_=strconv.ParseInt(pos,0,64)v=ans[idx]ifmid>=i{ifv==""{ans[idx]="-"}else{ans[idx]=v+" -"}continue}ifv==""{ans[idx]=val}else{ans[idx]=v+" "+val}}fmt.Println(strings.TrimSpace(strings.Join(ans," ")))}funcreadLine(reader*bufio.Reader)string{str,_,err:=reader.ReadLine()iferr==io.EOF{return""}returnstrings.TrimRight(string(str),"\r\n")}
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 →
Golang You can not pass the tests. Do replace main function loop and write logic directly.