Coding Interview | Fraud Transactions
I recently interviewed with a coding problem about fraudulent transactions, so I am recording it here.
The problem roughly gave me a transaction list:
record Transaction(
String accountHolderName,
int amount,
String location,
LocalTime timeStamp
)
I had to find the fraudulent transactions under two rules:
- A single transaction with an amount greater than $2,000 is immediately considered fraudulent.
- Transactions from the same account within 60 minutes are also considered fraudulent if they occur in different locations.
I first confirmed the input definition and the fraud criteria. The problem did not emphasize any constraints on the data size or time range, so I treated it as a regular list input.
My approach was straightforward. I first filtered the transactions whose amounts were greater than $2,000. Then, for each account, I used a nested loop to compare its other transactions and checked whether their locations differed and whether their timestamps were within 60 minutes.
The main edge cases I considered were:
- Transactions in the same location are not fraudulent.
- Whether exactly 60 minutes counts as being within the window.
- Multiple transactions from the same account within a short time.
- An amount of exactly $2,000 is not fraudulent.
While coding, I basically explained as I wrote, describing why I wrote each line. At the end, we also discussed time and space complexity.
The problem itself was not especially difficult. It felt like the main things being tested were basic coding ability, edge cases, and whether I could explain my reasoning clearly. I hope everyone has a smooth process.
I recently interviewed with a coding problem about fraudulent transactions, so I am recording it here.
The problem roughly gave me a transaction list:
record Transaction(
String accountHolderName,
int amount,
String location,
LocalTime timeStamp
)
I had to find the fraudulent transactions under two rules:
- A single transaction with an amount greater than $2,000 is immediately considered fraudulent.
- Transactions from the same account within 60 minutes are also considered fraudulent if they occur in different locations.
My approach was straightforward. I first filtered the transactions whose amounts were greater than $2,000. Then, for each account, I used a nested loop to compare its other transactions and checked whether their locations differed and whether their timestamps were within 60 minutes.
During the interview, I mostly explained as I wrote. I needed to explain why I wrote each line, and at the end I was also asked about time and space complexity.
The problem itself was not especially difficult. It felt like the main things being tested were basic coding ability, edge cases, and whether I could explain my reasoning clearly. I hope everyone has a smooth process.
Discussion
Loading comments…