Find Members With Gaps in Monthly Premium Payments
Last updated: November 29, 2026
Quick Overview
Given a premium_payments table (member_id, coverage_month, amount_paid), write SQL that lists every gap where a member paid for a month, skipped one or more months, and later paid again, with the gap start, gap end and number of missed months.
Cognizant
November 29, 20260
0
0 solved
Given a premium_payments table (member_id, coverage_month, amount_paid), write SQL that lists every gap where a member paid for a month, skipped one or more months, and later paid again, with the gap start, gap end and number of missed months.
Payer clients use Cognizant data teams to build reporting for grace periods and coverage terminations, which hinge on missed premium months. The interviewer checks gaps-and-islands thinking with window functions, deduplication of partial payments, and careful month arithmetic.
What the Interviewer Expects
- Deduplicates multiple payments in the same month
- Uses LAG partitioned by member and ordered by month
- Computes missed months with year times 12 plus month arithmetic
- Excludes zero or negative payments explicitly
- Explains why leading and trailing gaps are not covered by this query
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 also find members whose most recent payment is more than two months ago?
- Payments can be partial. How would you treat a month paid at 40 percent of the premium?
- How would you turn this into an incremental daily job instead of a full recompute?
- How would you write the same query with a calendar table instead of LAG?
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
coverage_month is a date; I will normalize it to the first of the month in case some rows use other days. A member can have several rows for one month (split payments, reversals), so I collapse to d...
Approach
Build distinct (member_id, month) pairs, then use LAG(month) over each member's ordered months. A gap exists when the previous paid month plus one month is earlier than the current month. Missed m...