(awards,k)
| 1 | def minimumGroups(awards,k): |
| 2 | |
| 3 | out=[] |
| 4 | awards.sort() |
| 5 | i=0 |
| 6 | count=0 |
| 7 | while(i<len(awards)): |
| 8 | count+=1 |
| 9 | count2=0 |
| 10 | temp=awards[i] |
| 11 | limit=0 |
| 12 | if(temp==awards[-1]): |
| 13 | i+=1 |
| 14 | for j in range(i+1,len(awards)): |
| 15 | count2+=1 |
| 16 | limit=abs(temp-awards[j]) |
| 17 | if(count2==len(awards)-1): |
| 18 | i+=count2+1 |
| 19 | |
| 20 | if(limit>k): |
| 21 | i+=count2 |
| 22 | break |
| 23 | |
| 24 | return count |
| 25 | awards=[1,13,6,8,9,3,5] # (or) awards=[3,1,4,3,9] |
| 26 | k=4 # (or) k=10 |
| 27 | print(minimumGroups(awards,k)) |