My issue
The question isn’t clear on the way of selecting the elements.
According to the 1st test case, I deduces that the selection of k elements should be done while preserving the original order of the elements in the original list.
Whereas the 2ns test case made me even more confused as they have selected the 2 elements without taking the order of the elements in the original list into consideration.
Please help me out if Im wrong.
My code
for t in range(int(input())):
n,k=list(map(int,input().split()))
a=sorted([*map(int,input().split())])
mxlst=a[k-1:]
mnlst=a[:-k+1]
m=float("inf")
for i in mxlst:
for j in mnlst:
nm=i-j
if nm<m:
m=nm
print(m)
Learning course: Jump from 2* to 3*
Problem Link: Fair distribution Practice Problem in Jump from 2* to 3* - CodeChef