Consecutive Tax Years

ASKED IN INTERVIEW
10pts
Intuit

Problem Statement

Find users who have filed taxes for 3 or more consecutive years.

Rules:

  • Output columns: user_id.
  • Definition: A sequence where Year N, Year N-1, and Year N-2 all exist for the same user.
  • Sort by user_id ASC.
Tests your understanding of
Window Functions, LEAD, LAG and Filtering

Input Tables

tax_filings
filing_id(INTEGER)user_id(INTEGER)tax_year(INTEGER)
112021
212022
312023
422021
522023
user_profiles
user_id(INTEGER)state(VARCHAR)
1CA
filing_types
filing_id(INTEGER)form_name(VARCHAR)
11040

Expected Output

user_id(INTEGER)
1

Tags

HardASKED IN INTERVIEWWindow FunctionsLEADLAGFiltering
30-40 min
39%

Hints