Particle Velocity - Company-specific OAs / Microsoft OA

https://algo.monster/problems/particle_velocity

You should wrap the solution text instead of having a horizontal scroll bar.

why 2 for loops? We only need 1 loop and compare prev velocity

def particleVelocity(particles):
# WRITE YOUR BRILLIANT CODE HERE
arr=[]
n=len(particles)
prevValue=particles[0]
arr.append(0)
for i in range(1,n):
arr.append(particles[i]-prevValue)
prevValue=particles[i]
prevValue=0
freq=0
count=0
for i in range(1,n):
if prevValue==arr[i]:
count+=freq
freq+=1
else:
prevValue=arr[i]
freq=1
return count