EASY PANDAS SOLLUTION, BEATS 99%
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem seems to involve analyzing sales data and filtering it based on specific cr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem seems to involve analyzing sales data and filtering it based on specific criteria. We are given two DataFrames: one containing product information and another containing sales data. The goal appears to be to filter the sales data to include only records that fall within a certain date range (January 1, 2019, to March 31, 2019) and then merge this filtered data with the product information to get a final DataFrame.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. First, we need to organize the sales data so we can work with it more easily. To do this, we group the sales data by each product (using \'product_id\') and find the earliest (\'min\') and latest (\'max\') sale dates for each product.\n2. Next, we need to filter the sales data to include only the records where the sale date falls between January 1, 2019, and March 31, 2019. This step ensures we\'re only looking at sales within our target date range.\n3. Now, we have a list of products that were sold during the specific time frame. We want to know the names of these products too, not just their IDs. To do this, we merge (combine) the filtered sales data with the product information. We match them using the \'product_id\', and we keep only the \'product_id\' and \'product_name\' for our final result.\n4. Return the resulting DataFrame as the answer.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nOverall time complexity is O(n).\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport pandas as pd\n\ndef sales_analysis(product: pd.DataFrame, sales: pd.DataFrame) -> pd.DataFrame:\n    # Group the \'sales\' DataFrame by \'product_id\' and calculate the minimum and maximum sale dates for each product\n    sales = sales.groupby(\'product_id\')[\'sale_date\'].agg([\'min\', \'max\']).reset_index()\n    \n    # Filter the sales data to include only records with sale dates between January 1, 2019, and March 31, 2019\n    sales = sales[(sales[\'min\'] >= \'2019-01-01\') & (sales[\'max\'] <= \'2019-03-31\')]\n    \n    # Merge the filtered sales data with the \'product\' DataFrame based on \'product_id\', keeping only \'product_id\' and \'product_name\' columns\n    result = pd.merge(sales, product, on=\'product_id\', how=\'inner\')[[\'product_id\', \'product_name\']]\n    \n    # Return the resulting DataFrame\n    return result\n\n```
['Pandas']