-
Notifications
You must be signed in to change notification settings - Fork 0
/
goldman sachs| invalid transactions
47 lines (38 loc) · 1.46 KB
/
goldman sachs| invalid transactions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
link:- https://leetcode.com/problems/invalid-transactions/
class Solution:
def invalidTransactions(self, transactions: List[str]) -> List[str]:
r = {}
inv = []
for i in transactions:
split = i.split(",")
name = str(split[0])
time = int(split[1])
amount = int(split[2])
city = str(split[3])
if time not in r:
r[time] = {
name: set([city]) # use set instead of list
}
else:
if name not in r[time]:
r[time][name]=set([city]) # use set instead of list
else:
r[time][name].add(city)
for i in transactions:
split = i.split(",")
name = str(split[0])
time = int(split[1])
amount = int(split[2])
city = str(split[3])
if amount > 1000:
inv.append(i)
continue
for j in range(time-60, time+61):
if j not in r:
continue
if name not in r[j]:
continue
if len(r[j][name]) > 1 or (next(iter(r[j][name])) != city): # get an element from set
inv.append(i)
break
return inv