Quick Overview

This question evaluates proficiency in data manipulation and relational reasoning using Python/pandas, focusing on transforming event logs into canonical pairwise relationships and extracting activation timestamps.

Generate Friendship List with Acceptance Dates Using Pandas

Company: Roblox

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Onsite

friend_events | requester_id | accepter_id | request_date | accept_date | |--------------|-------------|--------------|-------------| | 1 | 2 | 2024-01-01 | 2024-01-02 | | 2 | 3 | 2024-01-03 | 2024-01-05 | | 3 | 2 | 2024-01-04 | 2024-01-05 | | 2 | 1 | 2024-01-06 | 2024-01-07 | | 4 | 1 | 2024-01-08 | 2024-01-09 | ##### Scenario After launching a social feature, product wants a list of confirmed friendships with the date they formed. ##### Question Given friend request logs, write Python/pandas that returns each distinct user pair once (smaller id first) and the acceptance date when the friendship became active. ##### Hints Filter accepted rows, sort ids, drop_duplicates.

Overview: This question evaluates proficiency in data manipulation and relational reasoning using Python/pandas, focusing on transforming event logs into canonical pairwise relationships and extracting activation timestamps.

You are given a log of friend requests and their acceptance dates. Each row represents a request from one user to another, along with the date it was requested and the date it was accepted. A confirmed friendship exists when there is a non-NULL accept_date. Write an SQL query that returns each distinct friendship pair exactly once (with the smaller user id as user1_id and the larger as user2_id) and the date when the friendship became active, defined as the earliest accept_date across all requests in either direction between the two users.

Tables

friend_events(requester_id INTEGER, accepter_id INTEGER, request_date DATE, accept_date DATE)

Hints

  1. Filter to accepted requests where accept_date IS NOT NULL.
  2. Canonicalize each pair so the smaller user id is always first.

Loading coding console...