Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Receipt Fraud Window Detection
00:00
5 left

Receipt Fraud Window Detection

MediumSQL · PostgreSQL

Problem

Write a query to identify users who scanned receipts from the same retailer within a five-minute window, indicating potential fraud at Fetch.

Use the provided scan records and consider consecutive scans by the same user at the same retailer. Exclude scans with missing timestamps or unmatched users and retailers.

Output

  1. One row per qualifying consecutive scan pair
  2. Include user_id, user_name, retailer_id, retailer_name, both scan IDs and timestamps, and seconds_between
  3. Order by user_id, then the later scan timestamp, then the later scan ID

Schema

users
ColumnTypeDescription
user_idPKINTFetch user identifier
user_nameVARCHAR(100)User display name
retailers
ColumnTypeDescription
retailer_idPKINTRetailer identifier
retailer_nameVARCHAR(120)Retailer display name
receipt_scans
ColumnTypeDescription
scan_idPKINTReceipt scan identifier
user_idINTUser who scanned the receipt
retailer_idINTRetailer associated with the receipt
scanned_atTIMESTAMPTZTimestamp when the receipt was scanned
Tablesusersretailersreceipt_scans
Interviewer

Your question is Receipt Fraud Window Detection. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.