Mutual Follows

MediumSQLSQL

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Table follows: follower_id INTEGER followee_id INTEGER (the pair is unique; nobody follows themselves) Two users are mutuals when each follows the other. Return every pair of mutuals once. Columns, in this order: the lower user id, the higher user id. Order by the first column, then the second.

Examples

Input: follows follower_id | followee_id 1 | 2 2 | 1 1 | 3
Output: 1 | 2
1 follows 3, but 3 does not follow back.

Constraints

  • Each pair appears once, not once per direction.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More SQL problems