Last active
May 21, 2020 15:54
my live-coding answer to some hackerrank problem as I was demoing tech interviewing to a mentee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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