Skip to content

Instantly share code, notes, and snippets.

@technikhil314
Created April 22, 2022 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technikhil314/adde52466934b3b0cf09fa2db5fb44e9 to your computer and use it in GitHub Desktop.
Save technikhil314/adde52466934b3b0cf09fa2db5fb44e9 to your computer and use it in GitHub Desktop.
Amazon transaction logs
function processLogs(logs, threshold) {
const n = logs.length;
let transactionCountMap = new Map()
for(let i=0;i<n;i++) {
const log = logs[i];
const [sender, recepient, amount] = log.split(" ");
transactionCountMap.set(sender, (transactionCountMap.get(sender) || 0) + 1)
if(sender !== recepient) {
transactionCountMap.set(recepient, (transactionCountMap.get(recepient) || 0) + 1)
}
}
const transactionCountEntries = Array.from(transactionCountMap.entries());
const overThreshholdUsers = transactionCountEntries.filter(x => x[1] >= threshold).map(x => x[0]);
return overThreshholdUsers.sort((x,y) => parseInt(x)-parseInt(y) > 0 ? 1 : -1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment