Created
April 22, 2022 16:37
-
-
Save technikhil314/adde52466934b3b0cf09fa2db5fb44e9 to your computer and use it in GitHub Desktop.
Amazon transaction logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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