AlgoMaster Logo

Find K Closest Elements

arr=[1, 2, 3, 4, 5],k=4,x=3
0 / 7
algomaster.io
Step:Start: sort the 5 elements by distance to x = 3, keep the 4 closest