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.
why my code is not correct? when i use intellij to run, result is correct, but when i copy code and paste it on hackerank is not correct?
This is Kotlin Solution :
importjava.util.*funmain(args:Array<String>){/* Enter your code here. Read input from STDIN. Print output to STDOUT. */valreader=Scanner(System.`in`)valn:Int=reader.nextInt()valarr2:Array<String>=Array(n){" "}for(iinarr2.indices){arr2[i]=readLine().toString()}countingSort(arr2)}funcountingSort(arr:Array<String>){valnumArr:Array<Int>=Array(arr.size){0}for(iinarr.indices){try{valnumberOnly:String=arr[i].filter{it.isDigit()}numArr[i]=numberOnly.toInt()}catch(e:NumberFormatException){}}valn=arr.sizevarmax=Int.MIN_VALUEfor(iin0untiln){max=maxOf(max,numArr[i])}valsum=Array(100){0}valcount:Array<Int>=Array(100){0}for(iin0untiln){count[numArr[i]]++}vark=1sum[0]=count[0]for(iin1..99){sum[k]=count[i]+sum[k-1]k++}for(iinsum.indices){print(sum[i].toString()+" ")}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 3
You are viewing a single comment's thread. Return to all comments →
why my code is not correct? when i use intellij to run, result is correct, but when i copy code and paste it on hackerank is not correct? This is Kotlin Solution :