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:

    1. Iterate through the DataFrame.
    2. Check if the student_id is equal to 101.
    3. If the condition is met, select the name and age for that student.
    4. Return the selected name and age.
  • 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...