Max Min, maxmin
1 def main (): 2 n = int (raw_input () 3 k = int (raw_input () 4 5 k_arr = [] 6 min_dif = 9999999999 # according to the input requirements, specify a maximum value of 7 8 for _ in xrange (n): 9 k_arr.append (int (raw_input () 10 11 k_arr.sort () # "orderliness" solves many problems 12 13 for _ in xrange (n-k + 1): 14 if k_arr [_ + k-1]-k_arr [_] <min_dif: # Compare "interval" 15 min_dif = k_arr [_ + k-1]-k_arr [_] 16 print min_dif17 18 main ()
Link:
Https://www.hackerrank.com/challenges/angry-children
Learning:
Abstract and abstract, and then find the corresponding relationship:
All questions are abstracted at the root, and then solved in the simplest way.
Mathematical and image-based
A lot of questions are expressed by mathematical formulas, or drawn pictures.
"Orderliness"
The ordered list processing can solve many problems.