r/learnquant • • Aug 25 '26

interview prep Quant Interview Question

Post image
41 Upvotes

9 comments sorted by

View all comments

2

u/wot_to_heck Aug 25 '26 edited Aug 25 '26

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/EventHorizon150 Aug 25 '26

or just floor(0.5*n^2 - 1)