Find subset with elements that are furthest apart from eachother

前端 未结 4 2106
野的像风
野的像风 2021-02-03 10:39

I have an interview question that I can\'t seem to figure out. Given an array of size N, find the subset of size k such that the elements in the subset are the furthest apart fr

4条回答
  •  忘了有多久
    2021-02-03 10:57

    I suppose your set is ordered. If not, my answer will be changed slightly.

    Let's suppose you have an array X = (X1, X2, ..., Xn)
    
    Energy(Xi) = min(|X(i-1) - Xi|, |X(i+1) - Xi|), 1 < i 

提交回复
热议问题