Student Record Manager - Problem
You are tasked with building a Student Record Management System that can store and manage student information efficiently.
Each student record contains:
- Name (string): Student's full name
- ID (integer): Unique student identifier
- Grades (array of integers): List of grades for different subjects
Your system should support the following operations:
- Add Student: Add a new student record to the system
- Search by ID: Find a student's complete record using their ID
- Calculate Average Grade: Compute the average of all grades for a specific student
For this problem, implement a function that takes a list of student records and a target student ID, then returns that student's average grade. If the student is not found, return -1.0.
Input & Output
Example 1 — Basic Student Record
$
Input:
students = [["Alice",101,[85,90,78]], ["Bob",102,[92,88,95]]], targetId = 102
›
Output:
91.67
💡 Note:
Student with ID 102 is Bob with grades [92,88,95]. Average = (92+88+95)/3 = 275/3 = 91.67
Example 2 — Student Not Found
$
Input:
students = [["Alice",101,[85,90,78]], ["Bob",102,[92,88,95]]], targetId = 999
›
Output:
-1.0
💡 Note:
No student has ID 999, so return -1.0 to indicate student not found
Example 3 — Single Grade
$
Input:
students = [["Charlie",103,[95]]], targetId = 103
›
Output:
95.0
💡 Note:
Student 103 has only one grade [95], so average is 95.0
Constraints
- 1 ≤ students.length ≤ 1000
- 1 ≤ student ID ≤ 106
- 1 ≤ grades.length ≤ 10
- 0 ≤ grade ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code