-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunfairness.py
More file actions
43 lines (22 loc) · 759 Bytes
/
unfairness.py
File metadata and controls
43 lines (22 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Solutions of the challenge proposed on Hackerrank at https://www.hackerrank.com/challenges/angry-children/problem
import math
import random
import re
import sys
# The minimum unfairness is can be found just by looking for the minimum difference between the first and the final
# element of all sublists.
def maxMin(k, arr):
arr = sorted(arr)
unfairs = [] # empty list in which storing all the unfairness values
for j in range(len(arr)-k+1):
unfairs.append(arr[j+k-1]-arr[j])
return min(unfairs)
if __name__ == '__main__':
n = int(input())
k = int(input())
arr = []
for _ in range(n):
arr_item = int(input())
arr.append(arr_item)
result = maxMin(k, arr)
print(str(result))