Skip to content

Commit 796f47b

Browse files
committed
Add solution #1169
1 parent ce3d4b4 commit 796f47b

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,162 LeetCode solutions in JavaScript
1+
# 1,163 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -910,6 +910,7 @@
910910
1161|[Maximum Level Sum of a Binary Tree](./solutions/1161-maximum-level-sum-of-a-binary-tree.js)|Medium|
911911
1162|[As Far from Land as Possible](./solutions/1162-as-far-from-land-as-possible.js)|Medium|
912912
1163|[Last Substring in Lexicographical Order](./solutions/1163-last-substring-in-lexicographical-order.js)|Hard|
913+
1169|[Invalid Transactions](./solutions/1169-invalid-transactions.js)|Medium|
913914
1189|[Maximum Number of Balloons](./solutions/1189-maximum-number-of-balloons.js)|Easy|
914915
1200|[Minimum Absolute Difference](./solutions/1200-minimum-absolute-difference.js)|Easy|
915916
1206|[Design Skiplist](./solutions/1206-design-skiplist.js)|Hard|
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* 1169. Invalid Transactions
3+
* https://leetcode.com/problems/invalid-transactions/
4+
* Difficulty: Medium
5+
*
6+
* A transaction is possibly invalid if:
7+
* - the amount exceeds $1000, or;
8+
* - if it occurs within (and including) 60 minutes of another transaction with the same name in
9+
* a different city.
10+
*
11+
* You are given an array of strings transaction where transactions[i] consists of comma-separated
12+
* values representing the name, time (in minutes), amount, and city of the transaction.
13+
*
14+
* Return a list of transactions that are possibly invalid. You may return the answer in any order.
15+
*/
16+
17+
/**
18+
* @param {string[]} transactions
19+
* @return {string[]}
20+
*/
21+
var invalidTransactions = function(transactions) {
22+
const parsed = transactions.map(t => {
23+
const [name, time, amount, city] = t.split(',');
24+
return { name, time: Number(time), amount: Number(amount), city };
25+
});
26+
27+
const invalid = new Set();
28+
29+
for (let i = 0; i < parsed.length; i++) {
30+
const current = parsed[i];
31+
if (current.amount > 1000) {
32+
invalid.add(i);
33+
}
34+
35+
for (let j = 0; j < parsed.length; j++) {
36+
const other = parsed[j];
37+
if (i !== j && current.name === other.name
38+
&& Math.abs(current.time - other.time) <= 60 && current.city !== other.city) {
39+
invalid.add(i);
40+
invalid.add(j);
41+
}
42+
}
43+
}
44+
45+
return [...invalid].map(index => transactions[index]);
46+
};

0 commit comments

Comments
 (0)