Given the table of user interactions with actions 'sent' and 'accepted', how would you find pairs of users who have not performed both actions on the same day?
💡 Model Answer
To identify user pairs that never have both a 'sent' and an 'accepted' action on the same date, you can use a self‑join or a NOT EXISTS subquery. One concise approach is:
SELECT s.user_id_sender, s.user_id_receiver
FROM interactions s
WHERE s.action = 'sent'
AND NOT EXISTS (
SELECT 1
FROM interactions a
WHERE a.user_id_sender = s.user_id_sender
AND a.user_id_receiver = s.user_id_receiver
AND a.action = 'accepted'
AND a.date = s.date);
This query starts with all 'sent' rows and filters out any pair that has a matching 'accepted' on the same date. The NOT EXISTS clause ensures that only pairs without a same‑day acceptance remain. Complexity is O(n) for the base scan plus O(n) for the subquery per row, but most engines optimize the NOT EXISTS into a single hash join, giving roughly linear time. If you prefer a set‑based solution, you can aggregate dates per action and then perform a left‑anti join between the two sets. Either method yields the desired list of pairs that never completed both actions on the same day.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500