Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,63 @@

1 Problem 1 : Group Sold Products by the Date (https://leetcode.com/problems/group-sold-products-by-the-date/)

----------------------------------------------

rite a solution to find for each date the number of different products sold and their names.

The sold products names for each date should be sorted lexicographically.

Return the result table ordered by sell_date.

The result format is in the following example.

------------------------------------------------
import pandas as pd

def group_sold_products(sold_products: pd.DataFrame) -> pd.DataFrame:
result = sold_products.groupby('sold_date')['product'].apply(lambda x: ','.join(sorted(x))).reset_index()
return result


------------------------------------------------


2 Problem 2 : Daily Leads and Partners ( https://leetcode.com/problems/daily-leads-and-partners/ )

----------------------------------------------
For each date_id and make_name, find the number of distinct lead_id's and distinct partner_id's.

Return the result table in any order.

The result format is in the following example.


------------------------------------------------
import pandas as pd

def daily_leads_partners(leads: pd.DataFrame) -> pd.DataFrame:
grouped = leads.groupby(['lead_date', 'partner_id']).size().reset_index(name='leads')
return grouped.sort_values(['lead_date', 'partner_id'])


------------------------------------------------

3 Problem 3 : Actors and Directors who Cooperated At Least Three Times (https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times/)
----------------------------------------------

rite a solution to find all the pairs (actor_id, director_id) where the actor has cooperated with the director at least three times.

Return the result table in any order.

The result format is in the following example.

------------------------------------------------
import pandas as pd

def actors_directors(actor_director: pd.DataFrame) -> pd.DataFrame:
counts = actor_director.groupby(['actor_id', 'director_id']).size().reset_index(name='num_movies')
result = counts[counts['num_movies'] >= 3][['actor_id', 'director_id']]
return result.sort_values(['actor_id', 'director_id'])


------------------------------------------------