Each Facebook Page's Top Post of the Week Including Ties

Last updated: November 29, 2026

Quick Overview

For every Facebook Page and calendar week, return the post or posts with the highest weighted engagement score, where score = reactions + 2 * comments + 3 * shares. If two posts tie, return both.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


For every Facebook Page and calendar week, return the post or posts with the highest weighted engagement score, where score = reactions + 2 * comments + 3 * shares. If two posts tie, return both.

Pages and creator analytics at Meta surface 'top post' modules, and the interviewer uses this to test whether you pick the ranking function that matches the business rule on ties. It also checks that you aggregate engagement before ranking.

What the Interviewer Expects
  • Aggregates engagement events to one score per post before ranking
  • Buckets posts into weeks with DATE_TRUNC on the post creation time
  • Chooses RANK or DENSE_RANK because ties must be kept
  • Partitions by page and week
  • Explains how ROW_NUMBER would silently drop a tied post
Key Topics to Cover
RANK
ties
top-N per group
DATE_TRUNC week
aggregation before ranking
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you return the top three posts per page per week, still keeping ties at the boundary?
  • Should a post be credited to the week it was created or the week the engagement happened? Defend one.
  • How would you normalize the score for Pages with very different follower counts?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Tables:

  • posts(post_id, page_id, created_at)
  • post_engagement_daily(post_id, ds, reactions, comments, shares), one row per post per day with activity.

I will credit all engagement to the week t...

Approach
  1. Sum engagement per post across all days.
  2. Left join to posts so zero-engagement posts get a score of 0.
  3. Compute the weighted score, bucket by DATE_TRUNC('week', created_at).
  4. RANK() wi...

Submit Your Answer
Markdown supported