Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Code Block
languagepy
themeMidnightDJango
titleMinimum Absolute Difference
linenumberstrue
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)
Code Block
languagepy
themeMidnightDJango
titleLuck Balance
linenumberstrue
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

...