Consider this shape, which shows up inside selection sort, bubble sort and every 'check all pairs' scan:
for (let i = 0; i < n; i++) for (let j = i + 1; j < n; j++) // exactly one comparison happens here
Write countComparisons(n) returning the exact number of comparisons performed — not a Big-O class, the precise count.
n = 0 and n = 1 both perform 0 comparisons- Return a plain number
n can be in the hundreds of thousands, and the tests are strict about speed — so derive the closed form rather than actually running the two loops