LeetCode 2888: Reshape Data: Concatenate

Problem Description

Explanation:

To concatenate two DataFrames vertically, we simply need to append the rows of the second DataFrame to the end of the rows of the first DataFrame. We can achieve this by creating a new DataFrame and copying all the rows from both input DataFrames into the new DataFrame.

  • Algorithmic Idea:

    1. Create a new empty DataFrame.
    2. Copy all the rows from the first DataFrame into the new DataFrame.
    3. Copy all the rows from the second DataFrame into the new DataFrame.
    4. Return the new concatenated DataFrame.
  • Time Complexity: O(m + n), where m and n are the number of rows in the two input DataFrames.

  • Space Complexity: O(m + n), for the new concatenated DataFrame.

Solutions

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class Solution {
    public List<List<Object>> concatenateDataFrames(List<List<Object>> df1, List<List<Object>> df2) {
        List<List<Object>> concatenatedDF = new ArrayList<>();
        
        concatenatedDF.addAll(df1);
        concatenatedDF.addAll(df2);
        
        return concatenatedDF;
    }
}

Loading editor...