PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Meta

Write queries for follows and bookings

Last updated: Mar 29, 2026

Quick Overview

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.

  • medium
  • Meta
  • Coding & Algorithms
  • Data Engineer

Write queries for follows and bookings

Company: Meta

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given tables/logs from a consumer app. Solve the following independent tasks. ## Part A — Active following as of a date (SQL) You have a follow event log: - `follow_events(follower_id, followee_id, event_type, event_ts)` - `event_type ∈ {'follow','unfollow'}` - A user can follow/unfollow the same person multiple times. **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: - If the latest event on or before `D` is `follow`, the relationship is active. - If the latest event is `unfollow`, it is inactive. - If there are no events on/before `D`, it should not appear. ## Part B — Add reciprocal friendships (SQL) 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. ## Part C — Mutual friends (Python) 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: - The graph can be large; aim for an efficient approach. ## Part D — Valid car bookings (Python) 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_id`s. Edge cases: - Back-to-back bookings where `end_time == next_start_time` do **not** overlap. - Input may be unsorted.

Quick Answer: 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.

Related Interview Questions

  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Array, Matrix, and Recommendation Problems - Meta (medium)
  • Find a String Containing Another - Meta (medium)
  • Solve Subarray Sum and Local Minimum - Meta (hard)
  • Validate abbreviations and brackets - Meta (medium)
Meta logo
Meta
Mar 1, 2026, 12:00 AM
Data Engineer
Technical Screen
Coding & Algorithms
20
0
Loading...

You are given tables/logs from a consumer app. Solve the following independent tasks.

Part A — Active following as of a date (SQL)

You have a follow event log:

  • follow_events(follower_id, followee_id, event_type, event_ts)
  • event_type ∈ {'follow','unfollow'}
  • A user can follow/unfollow the same person multiple times.

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:

  • If the latest event on or before D is follow , the relationship is active.
  • If the latest event is unfollow , it is inactive.
  • If there are no events on/before D , it should not appear.

Part B — Add reciprocal friendships (SQL)

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.

Part C — Mutual friends (Python)

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:

  • The graph can be large; aim for an efficient approach.

Part D — Valid car bookings (Python)

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:

  • Back-to-back bookings where end_time == next_start_time do not overlap.
  • Input may be unsorted.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Data Engineer•Meta Data Engineer•Meta Coding & Algorithms•Data Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.