AP Moller - Maersk Interview Questions
This is a self join problem where a single stations table is joined twice to resolve two foreign keys (departure and destination) into human readable na...
SQL: Retrieve train name along with departure and destination station names.
This is a self join problem where a single stations table is joined twice to resolve two foreign keys (departure and destination) into human readable names. Assuming the schema: trains(train id, train name, departure station id, destination station id) stations(station id, station name) Key technique : Aliasing the same table twice ( dep and dest ) allows a single stations lookup table to serve both roles — a fundamental SQL pattern called a role playing dimension in data warehousing. Variant wi
Python: Given sales data as dictionaries, calculate total sales for each region for a given year. Write a Python code to calculate the total sales for each region for a given year. The function should filter the data by year and return a dictionary with regions and total sales as keys. data=[ {"date": "2023-01-15", "region": "North", "sales_amount": 1500}, {"date": "2023-02-20", "region": "South", "sales_amount": 1200}, {"date": "2023-02-21", "region": "South", "sales_amount": 1300}, {"date": "2022-03-10", "region": "North", "sales_amount": 1800}, {"date": "2023-04-05", "region": "East", "sales_amount": 2000}] year = 2023 Expected Output: {North: 1500, South: 2500, East: 2000} year=2022 Expected Output: {North: 1800}
A clean solution uses collections.defaultdict for aggregation after filtering by year: Alternative with Pandas (preferred in data engineering): Time complexity : O(n) — single pass through the list. Key point : Parsing year from the ISO date string with split(" ")[0] is simple; using datetime.strptime or pd.to datetime is more robust for malformed dates.