This question evaluates the ability to manipulate temporal event logs, enforce bidirectional relational integrity, and implement efficient graph and interval algorithms using SQL and Python.
You are given tables/logs from a consumer app. Solve the following independent tasks.
You have a follow event log:
follow_events(follower_id, followee_id, event_type, event_ts)
event_type ∈ {'follow','unfollow'}
Task: Given a parameter date D (inclusive), return all active follow relationships at the end of day D (i.e., after all events with event_ts <= D 23:59:59).
Output columns:
as_of_date
(value =
D
),
follower_id
,
followee_id
Clarifications/edge cases to handle:
D
is
follow
, the relationship is active.
unfollow
, it is inactive.
D
, it should not appear.
You have a directed friendship table:
friendships(user_id, friend_id)
A friendship should be bidirectional (if (A,B) exists, (B,A) should also exist).
Task: Produce the set of missing reciprocal rows that must be inserted to make the data bidirectional, without creating duplicates.
Output columns: user_id, friend_id representing rows to insert.
You are given an undirected friendship list edges, where each element is a pair (u, v) meaning u and v are friends.
Task: Implement a function that returns the set (or sorted list) of mutual friends of two users a and b.
Constraints to consider:
A single car can be booked by only one customer at a time.
You are given booking requests as a list of tuples (booking_id, start_time, end_time), where start_time < end_time.
Rule: Accept bookings in increasing start_time order; a booking is valid/accepted if it does not overlap with any previously accepted booking.
Task: Return the list of accepted booking_ids.
Edge cases:
end_time == next_start_time
do
not
overlap.