Check my formula to compute ans in O(n)

lets say there are three components of size 4,3,2 so ans will be
=4*(tot-4)+3*(tot-4-3)
where tot=4+3+2=9

Yes your formula is giving the expected output.

1 Like