You are viewing a single comment's thread. Return to all comments →
Brilliant idea @zh2196! Here's my implementation in Python (passes all test cases):
def compute_score(group_1, group_2): score = 0 for i in group_1: for j in group_2: score += abs(i - j) return score def fairCut(k, arr): arr.sort() if 2 * k > n: k = n - k start = (len(arr) - 2 * k) // 2 stop = start + 2 * k group_1, group_2 = [], [] for i in range(len(arr)): if stop >= i >= start and (i - start) % 2 == 1: group_1.append(arr[i]) else: group_2.append(arr[i]) return compute_score(group_1, group_2)
Seems like cookies are disabled on this browser, please enable them to open this website
Fair Cut
You are viewing a single comment's thread. Return to all comments →
Brilliant idea @zh2196! Here's my implementation in Python (passes all test cases):