Max Min, maxmin

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.