a = [6, 5, 4, 2, 6] # 1 . continuous integers randomly sorted # 2. min, max # 3. missing -> 3 # 4. duplicate -> 6 # similar to this hard LC question # https://leetcode.com/problems/first-missing-positive/ def detect(l): pass assert detect(a) == (3, 6) [2,4,5,6,6]=23 [2,3,4,5,6]=17 min=2 max=6 ===== 6:2 2:1 5:1 4:1 ===== 2,3 sum(keys)=17 min=2 max=6 max-min=4 [1,2,4] [1,2,3] min+...+max expect 2+3+4+5+6 20 actual 23 2+3+4+5+6=20 2+4+5+6+6=23 missing = sum(actual) - sum(expected) duplicate =