Palantir Coding Challenge

Fountain Head
2 min readNov 4, 2017

--

Today I solved a HackerRank coding challenge created by Palantir. I applied online and they unfortunately didn’t directly start with a phone interview. The question was a long one, it personally took me 15 mins to understand it. Maybe my gears need some maintenance on that.

The question was called “Detecting Contractor Fraud”. There are two types of fraud here: one is submitting an invoice number smaller than a previous one submitted by some other contractor, and submitting a batch of invoices, not necessarily in order, that contain unfitting invoice numbers.

My partial answer solves the first problem.

/*
* Complete the function below.
*/
static String[] findViolations(String[] datafeed) {

List<String> res = new LinkedList<>();

long min = Long.MIN_VALUE;

// Map for < contractor - <Line number, previous invoice number> > mapping
Map<String, Pair> hm = new HashMap<>();

int lines = 1;

for(String data : datafeed){

String[] input = data.split(";");

if(input[1].equals("START")){

hm.put(input[0], new Pair(lines, min));
}else{

String[] invoices = input[1].split(",");
if(invoices.length == 1){
Pair entry = hm.get(input[0]);
if(Long.parseLong(invoices[0]) < entry.y){
String fraud = "" + entry.x + ";" + input[0] + ";" + "SHORTENED_JOB";
res.add(fraud);
}else{
min = Long.parseLong(invoices[0]);
}
}else{

// COULDN'T COMPLETE THIS PART. BUT THE IDEA WOULD BE TO SORT INVOICES IN THE BATCH AND
// COMPARE WITH PERVIOUS ENTRIES.

/*Pair entry = hm.get(input[0]);
boolean fraud = false;
for(String invoice : invoices){
if(Long.parseLong(invoice) < entry.y){
fraud = true;
}
}
if(fraud){
String fraud = "" + entry.x + ";" + input[0] + ";" + "SUSPICIOUS_BATCH";
res.add(fraud);
}else{
min = Long.parseLong(invoices[0]);
}*/

}
}

lines++;

}

String[] ans = res.toArray(new String[res.size()]);
return ans;
}

static class Pair{
// x : line number
int x;
// y : previous invoice number record
long y;
Pair(int x, long y){
this.x = x;
this.y = y;
}
}

--

--