Most Recent Post per Facebook Page With Deterministic Tie Breaking
Last updated: November 29, 2026
Quick Overview
For each Facebook Page, return its single most recent published post. Several posts can share the same timestamp because of scheduled publishing, so the result must be stable across runs.
Meta
November 29, 20260
0
0 solved
For each Facebook Page, return its single most recent published post. Several posts can share the same timestamp because of scheduled publishing, so the result must be stable across runs.
Scheduled posts on Pages often publish in the same second, and Meta phone screens use this to see whether you think about ties. The interviewer checks ROW_NUMBER versus RANK and a stable secondary sort key.
What the Interviewer Expects
- Uses ROW_NUMBER partitioned by page
- Orders by published time then post_id
- Explains RANK would return multiple rows on ties
- Filters out unpublished or deleted posts first
- Avoids the join-back-on-max-timestamp pattern that duplicates ties
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you return the latest three posts per page?
- What if you wanted all tied posts?
- How would you do this efficiently for millions of pages?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
page_posts(post_id, page_id, published_at, status). Status in ('published', 'scheduled', 'deleted'). Only published posts count. post_id is unique and increasing, so it is a safe tie-breaker....
Approach
The tempting pattern is: compute MAX(published_at) per page and join back to the posts table on (page_id, published_at). With ties, that join returns two or more posts for a page. A window function ...