I’m posting this as Mockvita 1 is over. I tried to solve this problem:
import math
def nCr(n, r):
if r > n-r:
r = n-r
ans = 1
for i in range(1, r+1):
ans *= n-r+i
ans //= i
return ans
c = int(input())
all_car_times = {}
for _ in range(c):
x, y, velocity = [int(x) for x in input().split()]
dist = math.sqrt(x*x + y*y)
time = dist / velocity
if time in all_car_times:
all_car_times[time] += 1
else:
all_car_times[time] = 1
total_collisions = 0
for val in all_car_times.values():
if val >= 2:
total_collisions += nCr(val, 2)
print(total_collisions)
But it’s passed public test cases only and failed in private test cases. Can anyone please figure out my fault?