← Pinterest Interview Insights
The 'strictly greater than' part is where I almost tripped up.
Break the problem into two parts: first, identify each user's first cancelled appointment timestamp; second, check if there exists any subsequent appointment with status 'returned' or 'confirmed' strictly after that timestamp. Then compute the percentage of users who have no such subsequent appointment.
Pro tip: Clarify the definition of 'first cancelled appointment'—it should be the earliest cancelled appointment per user, not just any cancelled appointment. Also, explicitly state how you handle ties (same timestamp) and users with no cancelled appointments.
Use a window function like ROW_NUMBER() partitioned by user_id and ordered by scheduled_timestamp to find the earliest cancelled appointment for each user.
For each user, check if there is any appointment with status 'returned' or 'confirmed' and scheduled_timestamp strictly greater than the first cancelled timestamp.
Use a LEFT JOIN or NOT EXISTS to filter users who have no such subsequent appointment after their first cancellation.
Count the number of such users and divide by the total number of users (or total users with at least one cancelled appointment, depending on interpretation), then multiply by 100.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.