Skip to content

Instantly share code, notes, and snippets.

@wenweixu
Created August 27, 2019 20:42
Show Gist options
  • Save wenweixu/77ec9a5d9512023de14ab9f4978546fa to your computer and use it in GitHub Desktop.
Save wenweixu/77ec9a5d9512023de14ab9f4978546fa to your computer and use it in GitHub Desktop.
Hackerrank Max Min python solution
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the maxMin function below.
def maxMin(k, arr):
arr.sort()
result = arr[k-1] - arr[0]
for i in range(n-k+1):
if arr[i+k-1] - arr[i] < result:
result = arr[i+k-1] - arr[i]
return result
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
k = int(input())
arr = []
for _ in range(n):
arr_item = int(input())
arr.append(arr_item)
result = maxMin(k, arr)
fptr.write(str(result) + '\n')
fptr.close()
@bogoreh
Copy link

bogoreh commented Nov 9, 2021

Thank so much

@Vikneshwaran207
Copy link

Bro I want to solve a program like this.
For only maximum points only as mentioned below
def maximumpoints(k,costs):
would you help me to solve this
I will attach the question also
IMG20220618211753
IMG20220618211803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment