Tell approach for it — "Find Index with minimum cost".

Revision en1, by rastogimudit02, 2025-04-07 21:02:37

Find Index with minimum cost

There are n indices from 1 to n.

Some indices are marked and given as input in an array (size m).

For the unmarked indices, find the index having the minimum cost.

Cost of an index is defined as -

the sum of reciprocal of absolute difference between this index and all other marked index.

$$$COST(i) = \sum_{m_{idx} \in \text{marked indices}} \frac{1}{|i - m_{idx}|}$$$

Constraint: 1 <= n, m <= 1e5

Tags coding

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English rastogimudit02 2025-04-07 21:02:37 530 Initial revision (published)