Nested Lists Problem

This Python program deals with the problem of handling and processing nested lists. The context of the problem is a school grading system where student names and their corresponding scores are taken as input. The goal is to find the students who have the second lowest score.

Secure your next interview 🎯

CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷

Here is the Nested Lists Problem HackerRank solution using CodeRankGPT:

The solution works by first taking the number of students as input and then for each student, their name and score are taken as input. These are stored in a nested list where each inner list represents a student and contains their name and score. The scores are also stored separately in a list. The unique scores are sorted and the second element from this sorted list is the second lowest score. A list comprehension is used to find the students who have this score and their names are sorted. Finally, the names of these students are printed, each on a new line.


if __name__ == "__main__":
    students = []
    scores = []
    for _ in range(int(input())):
        name = input()
        score = float(input())
        student = [name, score]
        students.append(student)
        scores.append(score)
    second_min_score = sorted(set(scores))[1]
    student_names = sorted(
        [student[0] for student in students if student[1] == second_min_score]
    )
    print("\n".join(student_names))

If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.

AI is here now, and other candidates might be using it to get ahead and win the job. 🧐

Built on Unicorn Platform