I'm trying this HackerRank problem. So far, I've ended up with this code :
n = int(raw_input())
ar = []
for i in xrange(n):
ar.append(raw_input().split())
output = [0] * 1000000
count = [0] * 100
for a in ar:
count[int(a[0])] += 1
total = 0
for a in xrange(100):
old = count[a]
count[a] = total
total += old
for a in ar:
if ar.index(a) < n/2:
output[count[int(a[0])]] = '-'
else:
output[count[int(a[0])]] = a[1]
count[int(a[0])] += 1
for o in output:
if type(o) != str:
break
else:
print o,
Out of 5 test cases, it only passed one. 2 were timed out because of high running time, but that's not my priority now. My priority is passing the other 2 test cases which completely failed. I can't figure where I could have gone wrong. I know I can probably make my code more efficient, but for now, I'm focusing on just getting the right output.
int()conversions once at the start - while loading the data. Split it, convert toint()and then doar.append. b) Same for replacing the first half with dashes, don't useoutput[count[int(a[0when know the first half right at the very top when loading them into the array. Load a dash instead for the first half. c) No need to makeoutputthat big, make it[0] * ninstead - lower memory use. d) Maybe skip thetype(o)test on every output and just print o.