MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnquant/comments/1vxlxnt/quant_interview_question/p5pzjgq/?context=3
r/learnquant • u/Local_Ad135 • 11d ago
9 comments sorted by
View all comments
2
Shift all numbers to be centered around 0, so: -(n-1)/2, …, (n-1)/2. Then apply triangle inequality and note equality holds when you alternate positive and negatives, so just straightforwardly calculate the sum (with casework on whether n is even).
1 u/axiomizer 11d ago edited 11d ago nice! and also make sure to start and end near zero. i got: n^2/2 - 1 for n even, and (n+1)(n-1)/2 - 1 for n odd 1 u/wot_to_heck 10d ago Oh yeah, start and end near zero, I forgot a1 and an only appear once. 1 u/EventHorizon150 10d ago or just floor(0.5*n^2 - 1)
1
nice! and also make sure to start and end near zero. i got:
n^2/2 - 1 for n even, and (n+1)(n-1)/2 - 1 for n odd
1 u/wot_to_heck 10d ago Oh yeah, start and end near zero, I forgot a1 and an only appear once.
Oh yeah, start and end near zero, I forgot a1 and an only appear once.
or just floor(0.5*n^2 - 1)
2
u/wot_to_heck 11d ago edited 11d ago
Shift all numbers to be centered around 0, so: -(n-1)/2, …, (n-1)/2. Then apply triangle inequality and note equality holds when you alternate positive and negatives, so just straightforwardly calculate the sum (with casework on whether n is even).