Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL or Python Fraud Anomaly Detection
00:00
5 left

SQL or Python Fraud Anomaly Detection

MediumSQL · PostgreSQL

Problem

Given a sample dataset of loan applications, how would you identify anomalies or potential fraudulent behavior using SQL or Python for Upstart?

Write a PostgreSQL query that flags applications with at least two anomaly indicators. Consider repeated applications by an applicant, devices or IP addresses shared by multiple applicants, and substantial differences between stated and application income.

Output

  1. One row per flagged application, including application_id, applicant_id, submitted_at, anomaly_score, and anomaly_reasons.
  2. Include only applications with an anomaly_score of at least 2.
  3. Order by anomaly_score descending, then submitted_at ascending, and application_id ascending.

Schema

loan_applications
ColumnTypeDescription
application_idPKINTEGERUnique loan application identifier
applicant_idINTEGERApplicant associated with the application
submitted_atTIMESTAMPApplication submission timestamp
annual_incomeNUMERIC(12,2)Annual income entered on the application
device_idVARCHAR(40)Device identifier observed at submission
ip_addressVARCHAR(45)IP address observed at submission
statusVARCHAR(40)Current application status
applicant_profiles
ColumnTypeDescription
applicant_idPKINTEGERUnique applicant identifier
stated_incomeNUMERIC(12,2)Income recorded in the applicant profile
Tablesloan_applicationsapplicant_profiles
Interviewer

Your question is SQL or Python Fraud Anomaly Detection. Start with the requirements and the two 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.