employer cover photo
employer logo
employer logo

Palantir Technologies

Is this your company?

Palantir Technologies interview question

Imagine you are working for a small bank, attempting to analyze fraudulent credit card transactions. You are given a list of strings describing credit card transactions for a single day. All strings are pipe‐delimited and will take the form of "<person name>|<integer whole dollar amount>|<location>|<integer time in minutes since 00:00>". The list is sorted in ascending order by time. Your job is to return a list of people's names whose accounts reflect suspicious activity. A person's account reflects suspicious activity if you see of the following: 1. A transaction spending more than $3000 2. A transaction for which the next transaction for the same person differs in location, and is less than an hour later The list you return should be ordered by when the first suspicious was detected. For the second type of fraud, consider the "first suspicious activity" to be the earlier of the two transactions. You have to complete the function getSuspiciousActivity to return the list of suspicious activities. The list you return should contain the person names as they appeared in the input. Please note that the first line of the input is the number of transactions in the array. Sample Input 1: Shilpa|500|California|63 Tom|25|New York|615 Krasi|9000|California|1230 Tom|25|New York|1235 Tom|25|New York|1238 Shilpa|50|Michigan|1300 Matt|90000|Georgia|1305 Jay|100000|Virginia|1310 Krasi|49|Florida|1320 Krasi|83|California|1325 Shilpa|50|California|1350 Sample Output 1: Krasi Shilpa Matt Jay Explanation Krasi is first because she has exhibited amount fraud before any other account exhibited either types of fraud (she then later also committed location fraud, but this doesn't matter). Shilpa is second, having committed location fraud where the first transaction took place before either of Matt or Jay's amount fraud. Matt and Jay both exhibited amount fraud, but Matt's fraud was recorded before Jay's. Tom is not on this list because he did not commit either type of fraud.

Interview Answers

Anonymous

21 Jun 2016

Hash map. The answer is almost always a hash map (+ a priority queue in this case).

Anonymous

5 Sept 2016

static String[] getSuspiciousList(String[] transactions) { //the priority queue is used to sort the final output names by time PriorityQueue output = new PriorityQueue(); //lastSeen is used to store the last seen person object for that name HashMap lastSeen = new HashMap(); //we use fraud to check if a person has been detected as a fraud already HashSet fraud = new HashSet(); int i = 0; for (i = 0; i 3000) { personToAddToOutput = p; fraudDetected = true; } if (lastSeen.containsKey(p.name)) { //we have seen this person before //we check if their location is different and it has been less than an hour Person last = lastSeen.get(p.name); if (!last.loc.equals(p.loc) && (p.time - last.time < 60)) { personToAddToOutput = last; fraudDetected = true; } } if (fraudDetected) { //we add this person as a fraud output.add(personToAddToOutput); fraud.add(p.name); } lastSeen.put(p.name,p); //update the last seen details for this person } //get only a list of names from the queue return getFinalOutput(output); }