Skip to content

Instantly share code, notes, and snippets.

@compwron
Last active May 21, 2020 15:54
Show Gist options
  • Save compwron/1a91e38c7a56b870cbb8ba3bcc4282fd to your computer and use it in GitHub Desktop.
Save compwron/1a91e38c7a56b870cbb8ba3bcc4282fd to your computer and use it in GitHub Desktop.
my live-coding answer to some hackerrank problem as I was demoing tech interviewing to a mentee
input = [5,
'Harry',
37.21,
'Berry',
37.21,
'Tina',
37.2,
'Akriti',
41,
'Harsh',
39]
def position_lowest_grade_student(position, input):
grades = {}
for i in range(0, len(input)):
if i == 0:
pass # do nothing with first value
elif i % 2 == 1: # is student name
name = input[i]
grade = input[i + 1]
grades[name] = grade
else:
pass
sorted_grades = sorted(grades.items(), key= lambda kv: (kv[1], kv[0]))
student_at_position = sorted_grades[position]
all_students_with_position_grade = [(k, v) for (k, v) in grades.items() if v == student_at_position[1]]
return sorted([k for (k, v) in all_students_with_position_grade])
print(position_lowest_grade_student(2, input)) # Berry, Harry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment