LeetCode 2880: Select Data
Problem Description
Explanation:
To solve this problem, we need to iterate through the DataFrame and select the rows where the student_id
is equal to 101. We then extract the name
and age
columns for that particular student.
-
Algorithm:
- Iterate through the DataFrame.
- Check if the
student_id
is equal to 101. - If the condition is met, select the
name
andage
for that student. - Return the selected
name
andage
.
-
Time Complexity: O(n) where n is the number of rows in the DataFrame.
-
Space Complexity: O(1) since we are not using any extra space proportional to the input.
:
Solutions
public List<List<Object>> selectData(List<List<Object>> students) {
List<List<Object>> result = new ArrayList<>();
for (List<Object> student : students) {
int studentId = (int) student.get(0);
if (studentId == 101) {
List<Object> selectedData = new ArrayList<>();
selectedData.add(student.get(1)); // name
selectedData.add(student.get(2)); // age
result.add(selectedData);
}
}
return result;
}
Loading editor...