LeetCode 2888: Reshape Data: Concatenate Solution

Master LeetCode problem 2888 (Reshape Data: Concatenate), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

2888. Reshape Data: Concatenate

Easy

Problem Explanation

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.

Solution Code

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;
    }
}

Try It Yourself

Loading code editor...

Frequently Asked Questions

How to solve LeetCode 2888 (Reshape Data: Concatenate)?

This page provides optimized solutions for LeetCode problem 2888 (Reshape Data: Concatenate) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 2888 (Reshape Data: Concatenate)?

The time complexity for LeetCode 2888 (Reshape Data: Concatenate) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 2888 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 2888 in Java, C++, or Python.

Back to LeetCode Solutions