Page tree
Skip to end of metadata
Go to start of metadata
Minimum Absolute Difference
def minimumAbsoluteDifference(arr):
    arr = sorted(arr)
    diff_arr = []
    
    for i in range(len(arr)-1):
        diff_arr.append(arr[i+1] - arr[i])
        
    return min(diff_arr)
Luck Balance
def luckBalance(k, contests):
    important_arr = []
    not_important_arr = []
    total = 0
    
    for contest in contests:
        if contest[1] == 1:
            important_arr.append(contest[0])
        else:
            total += contest[0]
    
    important_arr = sorted(important_arr, reverse=True)
    
    for n in important_arr:
        if k > 0:
            total += n
            k = k - 1
        else:
            total -= n
        
    return total
 
  • No labels