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.
It's okay because "that's what the client wants" - I created a second list variable with "-" if i < n/2, but I don't think it was necessary because the original list is never used.
defcountSort(n,arr):#useninsteadoflen(arr)forlinarr:l[0]=int(l[0])#convertfirstlistitemtointegerforiinrange(n//2): # replace first half with hyphenarr[i][1]="-"# sort by number into empty list arrayoutput=[[]for_inrange(n)]forlinarr:output[l[0]].append(l[1])print(' '.join(jforiinoutputforjini))
Independently, here is my Python3 code, which is similar but has no execution time wasted in if statements. In modern HackerRank, the inputs are already taken in the main method, and we fill-in the given method. In GeoMatt22's simplification of abehjat's C-to-Python code, the sorting according to key was excluded accidentally and str is a reserved word, meaning the suggested code is untested? This sorting challenge does not involve a counting sort, as the string values are not repeated from a small fixed list of possibilities.
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →
Simple to read Python solution
ok, but by replacement linX = "-" you are losing original strings from input.
Ah! Good point. I could set up two list variables (one stores the original array, and the other contains the modified array)
It's okay because "that's what the client wants" - I created a second list variable with "-" if i < n/2, but I don't think it was necessary because the original list is never used.
Great Solution
brilliant code
arent you supposed to use counting sort in the "challange"?
This code is good. Although, you should not name objects the same as restricted keywords in python, such as 'list'
Using sort now fails some of the test cases.
Here is my code
good code . but y is it giving runtime error here
Nice solution!
A more concise (but perhaps less clear?) Python 3 translation might be:
Independently, here is my Python3 code, which is similar but has no execution time wasted in
if
statements. In modern HackerRank, the inputs are already taken in the main method, and we fill-in the given method. In GeoMatt22's simplification of abehjat's C-to-Python code, the sorting according to key was excluded accidentally andstr
is a reserved word, meaning the suggested code is untested? This sorting challenge does not involve a counting sort, as the string values are not repeated from a small fixed list of possibilities.Awesome code though. slight improvisation in output part.