A transaction is possibly invalid if:

the amount exceeds $1000, or;
if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.

Each transaction string transactions[i] consists of comma separated values representing the name, time (in minutes), amount, and city of the transaction.
Given a list of transactions, return a list of transactions that are possibly invalid.  You may return the answer in any order.
 
Example 1:
Input: transactions = ["alice,20,800,mtv","alice,50,100,beijing"]
Output: ["alice,20,800,mtv","alice,50,100,beijing"]
Explanation: The first transaction is invalid because the second transaction occurs within a difference of 60 minutes, have the same name and is in a different city. Similarly the second one is invalid too.
Example 2:
Input: transactions = ["alice,20,800,mtv","alice,50,1200,mtv"]
Output: ["alice,50,1200,mtv"]

Example 3:
Input: transactions = ["alice,20,800,mtv","bob,50,1200,mtv"]
Output: ["bob,50,1200,mtv"]

 
Constraints:

transactions.length <= 1000
Each transactions[i] takes the form "{name},{time},{amount},{city}"
Each {name} and {city} consist of lowercase English letters, and have lengths between 1 and 10.
Each {time} consist of digits, and represent an integer between 0 and 1000.
Each {amount} consist of digits, and represent an integer between 0 and 2000.

Difficulty: MEDIUM
Tags: String algorithms

Sorting

Data structures
Skill types: Sorting

Data structures

Starter code:
class Solution:
    def invalidTransactions(self, transactions: List[str]) -> List[str]:
        

Solutions:
class Transaction:

	def __init__(self, s):
		params = s.split(',')
		(self.name, self.time, self.amount, self.city) = (params[0], int(params[1]), int(params[2]), params[3])

	def __str__(self):
		return ','.join([self.name, str(self.time), str(self.amount), self.city])

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		transactions = [Transaction(t) for t in transactions]
		transactions.sort(key=lambda t: t.time)
		trans_idxs = defaultdict(list)
		for (i, t) in enumerate(transactions):
			trans_idxs[t.name].append(i)
		invalid = []
		for (name, idxs) in list(trans_idxs.items()):
			left = right = 0
			for trans_idx in idxs:
				t = transactions[trans_idx]
				if t.amount > 1000:
					invalid.append(str(t))
					continue
				while left <= len(idxs) - 2 and transactions[idxs[left]].time < t.time - 60:
					left += 1
				while right <= len(idxs) - 2 and transactions[idxs[right + 1]].time < t.time + 60:
					right += 1
				for j in range(left, right + 1):
					if transactions[idxs[j]].city != t.city:
						invalid.append(str(t))
						break
		return invalid


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		(record, res) = (collections.defaultdict(list), set())
		for trans in transactions:
			(name, time, amount, city) = trans.split(',')
			(amount, time) = (int(amount), int(time))
			if amount > 1000:
				res.add(trans)
			if name in record:
				(i, j) = (bisect.bisect_left(record[name], (time - 60, '', 0)), bisect.bisect_right(record[name], (time + 61, '', 0)))
				valid = True
				for item in record[name][i:j]:
					if item[1] != city:
						valid = False
						res.add(','.join([name, str(item[0]), str(item[2]), item[1]]))
				if not valid:
					res.add(trans)
			bisect.insort(record[name], (time, city, amount))
		return list(res)


import collections

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:

		def parse(S):
			fields = S.split(',')
			return [fields[0], int(fields[1]), int(fields[2]), fields[3]]
		hashMap = defaultdict(list)
		for S in transactions:
			fields = parse(S)
			hashMap[fields[0]].append(fields[1:])
		invalid = set([])
		for key in hashMap:
			vals = hashMap[key]
			for (i, val1) in enumerate(vals):
				if val1[1] >= 1000:
					invalid = invalid.union(set([','.join([key, str(val1[0]), str(val1[1]), val1[2]])]))
				if len(vals) <= 1:
					continue
				for (j, val2) in enumerate(vals[i + 1:]):
					if abs(val1[0] - val2[0]) <= 60 and val1[2] != val2[2]:
						invalid = invalid.union(set([','.join([key, str(val1[0]), str(val1[1]), val1[2]])]))
						invalid = invalid.union(set([','.join([key, str(val2[0]), str(val2[1]), val2[2]])]))
		return list(invalid)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		temp = []
		for t in transactions:
			temp.append(t.split(','))
		temp = sorted(temp, key=lambda x: x[0])
		res = set()
		for i in range(len(temp)):
			if int(temp[i][2]) > 1000:
				res.add(','.join(temp[i]))
			for j in range(i + 1, len(temp)):
				if temp[i][0] == temp[j][0] and temp[i][3] != temp[j][3] and (abs(int(temp[i][1]) - int(temp[j][1])) <= 60):
					res.add(','.join(temp[i]))
					res.add(','.join(temp[j]))
		return res


from collections import defaultdict

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		out_idx = set()
		q = []
		bkt_max = -inf
		for (idx, transaction) in enumerate(transactions):
			(name, time, amount, city) = transaction.split(',')
			time = int(time)
			amount = int(amount)
			if amount > 1000:
				out_idx.add(idx)
			bkt_max = max(bkt_max, time + 30)
			q.append((max(time - 30, 0), time + 30, name, city, idx))
		bkt = [None] * (bkt_max + 1)
		for (time_lower_bound, time_upper_bound, name, city, idx) in q:
			for i in range(time_lower_bound, time_upper_bound + 1):
				if bkt[i] is None:
					bkt[i] = defaultdict(lambda : defaultdict(lambda : set()))
				bkt[i][name][city].add(idx)
		for b in bkt:
			if b is not None:
				for (k, v) in list(b.items()):
					if len(v) > 1:
						for v1 in list(v.values()):
							out_idx.update(v1)
		out = []
		for idx in out_idx:
			out.append(transactions[idx])
		return out


class Solution:
	from heapq import heappush, heappop

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		if not transactions:
			return []
		memo = collections.defaultdict(list)
		invalid_tran = set()
		for i in range(len(transactions)):
			(name, time, amount, city) = (int(i) if i.isnumeric() else i for i in transactions[i].split(','))
			if amount > 1000:
				invalid_tran.add(transactions[i])
			if name in memo:
				for tran in memo[name]:
					(_, prev_time, _, prev_city) = (int(i) if i.isnumeric() else i for i in tran.split(','))
					if abs(time - prev_time) <= 60 and prev_city != city:
						invalid_tran.add(tran)
						invalid_tran.add(transactions[i])
			memo[name].append(transactions[i])
		return invalid_tran


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		parsed_ts = []
		invalid_ts = set()
		for t in transactions:
			t_list = t.split(',')
			t_dict = {}
			t_dict['str'] = t
			t_dict['name'] = t_list[0]
			t_dict['time'] = int(t_list[1])
			t_dict['amount'] = int(t_list[2])
			t_dict['city'] = t_list[3]
			if t_dict['amount'] > 1000:
				invalid_ts.add(t)
			for t2 in parsed_ts:
				if abs(t_dict['time'] - t2['time']) <= 60 and t_dict['city'] != t2['city'] and (t_dict['name'] == t2['name']):
					invalid_ts.add(t_dict['str'])
					invalid_ts.add(t2['str'])
			parsed_ts.append(t_dict)
		return list(invalid_ts)


class Transaction:

	def __init__(self, name, time, amount, city):
		self.name = name
		self.time = int(time)
		self.amount = int(amount)
		self.city = city

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		for i in range(len(transactions)):
			transact = transactions[i].split(',')
			transactions[i] = Transaction(transact[0], transact[1], transact[2], transact[3])
		invalid = set()
		transactions.sort(key=lambda t: t.time)
		for (i, t) in enumerate(transactions):
			if t.amount > 1000:
				invalid.add(self.toString(t))
			for j in range(i + 1, len(transactions)):
				s = transactions[j]
				if t.name == s.name and t.city != s.city and (s.time - t.time <= 60):
					invalid.add(self.toString(s))
					invalid.add(self.toString(t))
		return invalid

	def toString(self, s):
		return '%s,%d,%d,%s' % (s.name, s.time, s.amount, s.city)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		n = len(transactions)
		invalid = []
		hashtime = {}
		hashcity = {}
		hashindex = {}
		for i in range(n):
			t = transactions[i].split(',')
			n = t[0]
			ti = int(t[1])
			a = int(t[2])
			c = t[3]
			if hashtime.get(n) is None:
				hashtime[n] = [ti]
				hashcity[n] = [c]
				hashindex[n] = [i]
			else:
				for h in range(len(hashindex[n])):
					li = hashtime[n][h]
					lc = hashcity[n][h]
					in1 = hashindex[n][h]
					if abs(li - ti) <= 60 and (not lc == c):
						if transactions[in1] not in invalid:
							invalid.append(transactions[in1])
						if transactions[i] not in invalid:
							invalid.append(transactions[i])
			if a > 1000:
				if transactions[i] not in invalid:
					invalid.append(transactions[i])
			hashtime[n].append(ti)
			hashcity[n].append(c)
			hashindex[n].append(i)
		return invalid


class Solution:

	def invalidTransactions(self, transactions):
		if not transactions:
			return []
		n = len(transactions)
		splits = [trans.split(',') for trans in transactions]
		valid = [True] * n
		for i in range(n):
			if int(splits[i][2]) > 1000:
				valid[i] = False
		for i in range(n):
			for j in range(i + 1, n):
				if valid[i] or valid[j]:
					(name1, time1, city1) = (splits[i][0], int(splits[i][1]), splits[i][3])
					(name2, time2, city2) = (splits[j][0], int(splits[j][1]), splits[j][3])
					if name1 == name2 and city1 != city2 and (abs(time1 - time2) <= 60):
						(valid[i], valid[j]) = (False, False)
		return [transactions[i] for i in range(n) if not valid[i]]


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		hash_table = {}
		invalid = []
		index = -1
		lindex = []
		for trans in transactions:
			count_coma = 0
			word = ''
			name = ''
			dl = []
			index += 1
			lenght = 0
			ind = 0
			for l in trans:
				lenght += 1
				if l == ',' or lenght == len(trans):
					count_coma += 1
					if count_coma == 1:
						name = word
					elif count_coma == 2:
						tl = [int(word)]
						dl.append(tl)
					elif count_coma == 3:
						if int(word) > 1000:
							ind = 1
					else:
						cl = [word]
						dl.append(cl)
						dl.append([index])
						if name not in hash_table:
							hash_table[name] = dl
							if ind == 1:
								invalid.append(trans)
								lindex.append(index)
						else:
							if ind == 1:
								invalid.append(trans)
								lindex.append(index)
							for i in range(0, len(hash_table.get(name)[0])):
								if abs(hash_table.get(name)[0][i] - dl[0][0]) < 61 and hash_table.get(name)[1][i] != dl[1][0]:
									if index not in lindex:
										invalid.append(trans)
										lindex.append(index)
									if hash_table.get(name)[2][i] not in lindex:
										invalid.append(transactions[hash_table.get(name)[2][i]])
										lindex.append(hash_table.get(name)[2][i])
							hash_table.get(name)[0].append(dl[0][0])
							hash_table.get(name)[1].append(dl[1][0])
							hash_table.get(name)[2].append(index)
					word = ''
				else:
					word += l
		return invalid


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		transactions_by_name = {}
		suspicious_transactions = set()
		for transaction in transactions:
			(name, time, amount, city) = transaction.split(',')
			if name not in transactions_by_name:
				transactions_by_name[name] = [[name, time, amount, city]]
			else:
				transactions_by_name[name].append([name, time, amount, city])
		for key in transactions_by_name.keys():
			for transaction in transactions_by_name[key]:
				for other_transaction in transactions_by_name[key]:
					if int(transaction[2]) >= 1000 and ','.join(transaction) not in suspicious_transactions:
						suspicious_transactions.add(','.join(transaction))
						continue
					if transaction == other_transaction:
						continue
					time_diff = abs(int(transaction[1]) - int(other_transaction[1]))
					print(time_diff)
					if time_diff <= 60 and transaction[3] != other_transaction[3]:
						suspicious_transactions.add(','.join(transaction))
		return list(suspicious_transactions)


class Solution(object):

	def invalidTransactions(self, transactions):
		(NAME, TIME, AMOUNT, CITY) = list(range(4))
		txrows = []
		for row in transactions:
			(name, time, amount, city) = row.split(',')
			time = int(time)
			amount = int(amount)
			txrows.append((name, time, amount, city))
		ans = []
		for (i, tx1) in enumerate(txrows):
			if tx1[AMOUNT] >= 1000:
				ans.append(transactions[i])
				continue
			for (j, tx2) in enumerate(txrows):
				if i != j and abs(tx1[TIME] - tx2[TIME]) <= 60 and (tx1[NAME] == tx2[NAME]) and (tx1[CITY] != tx2[CITY]):
					ans.append(transactions[i])
					break
		return ans


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:

		def parseTransaction(t):
			vals = t.split(',')
			return (vals[0], int(vals[1]), int(vals[2]), vals[3])
		invalid = set()
		names = {}
		for t in transactions:
			(name, time, amt, city) = parseTransaction(t)
			if amt > 1000:
				invalid.add(t)
			if name in names:
				for (other_t, other_time, other_city) in names[name]:
					if other_city != city and abs(other_time - time) <= 60:
						invalid.add(other_t)
						invalid.add(t)
			else:
				names[name] = []
			names[name].append((t, time, city))
		return list(invalid)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		seen = {}
		final = []
		for i in transactions:
			j = i.split(',')
			name = j[0]
			time = int(j[1])
			amount = int(j[2])
			city = j[3]
			if name not in seen:
				seen[name] = [[name, time, amount, city, i]]
			else:
				seen[name].append([name, time, amount, city, i])
		for key in list(seen.keys()):
			keys_by_time = {}
			for i in range(len(seen[key])):
				keys_by_time[seen[key][i][1]] = i
			seen[key].append(keys_by_time)
		for key in list(seen.keys()):
			for i in range(len(seen[key]) - 1):
				for j in range(i + 1, len(seen[key]) - 1):
					current = seen[key][i]
					nex = seen[key][j]
					if current[3] != nex[3] and abs(current[1] - nex[1]) <= 60:
						if current[4] not in final:
							final.append(current[4])
						if nex[4] not in final:
							final.append(nex[4])
				if seen[key][i][4] not in final and seen[key][i][2] > 1000:
					final.append(seen[key][i][4])
		return final


class dsu:

	def __init__(self, n):
		self.parent = [x for x in range(n)]
		self.rank = [0 for x in range(n)]
		self.valid = [True for x in range(n)]
		self.n = n

	def find(self, x):
		if self.parent[x] != x:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, s, t):
		(sp, tp) = (self.find(s), self.find(t))
		if sp == tp:
			return
		if self.rank[sp] < self.rank[tp]:
			self.parent[sp] = tp
		elif self.rank[sp] > self.rank[tp]:
			self.parent[tp] = sp
		else:
			self.parent[tp] = sp
			self.rank[sp] += 1

	def cluster(self):
		for x in range(self.n):
			self.find(x)

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		arrlen = len(transactions)
		net = dsu(arrlen)
		tplist = [t.split(',') for t in transactions]
		for i in range(arrlen):
			tp = tplist[i]
			(name, time, amt, city) = (tp[0], tp[1], tp[2], tp[3])
			if int(amt) > 1000:
				net.valid[i] = False
			for j in range(i + 1, arrlen):
				jtp = tplist[j]
				(jname, jtime, jamt, jcity) = (jtp[0], jtp[1], jtp[2], jtp[3])
				if jname == name and jcity != city and (abs(int(jtime) - int(time)) <= 60):
					net.union(i, j)
		net.cluster()
		for i in range(arrlen):
			if net.parent[i] != i or net.rank[i] != 0:
				net.valid[i] = False
		return [transactions[i] for i in range(arrlen) if not net.valid[i]]


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		res = []
		for i in range(len(transactions)):
			action = transactions[i].split(',')
			person = action[0]
			time = action[1]
			amt = action[2]
			city = action[3]
			if int(amt) > 1000:
				res.append(transactions[i])
			for j in range(i + 1, len(transactions)):
				act2 = transactions[j].split(',')
				if act2[0] == person and abs(int(act2[1]) - int(time)) <= 60 and (city != act2[3]):
					res.extend([transactions[i], transactions[j]])
		return list(set(res))


class Solution:

	def invalidTransactions(self, transactions):
		transactions = [t.split(',') for t in transactions]
		t = defaultdict(list)
		res = set()
		for x in transactions:
			t[x[0]].append([int(x[1]), int(x[2]), x[3]])
		for name in t:
			t[name].sort(key=lambda x: x[0])
			for i in range(len(t[name])):
				(time1, amount1, city1) = t[name][i]
				if amount1 > 1000:
					res.add(','.join([name, str(time1), str(amount1), city1]))
				for j in range(i + 1, len(t[name])):
					(time2, amount2, city2) = t[name][j]
					if amount2 > 1000:
						res.add(','.join([name, str(time2), str(amount2), city2]))
					if city1 == city2:
						continue
					if time2 - time1 <= 60:
						res.add(','.join([name, str(time1), str(amount1), city1]))
						res.add(','.join([name, str(time2), str(amount2), city2]))
					else:
						break
		return res


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		res = []
		records = []
		for t in transactions:
			rec = t.split(',')
			rec[1] = int(rec[1])
			rec[2] = int(rec[2])
			records.append(rec)
		for rec in records:
			if rec[2] > 1000:
				rec[1] = str(rec[1])
				rec[2] = str(rec[2])
				res.append(','.join(rec))
				continue
			for x in records:
				if rec[0] == x[0] and abs(rec[1] - int(x[1])) <= 60 and (rec[3] != x[3]):
					rec[1] = str(rec[1])
					rec[2] = str(rec[2])
					res.append(','.join(rec))
					break
		return res


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		if not transactions:
			return []
		res = set()
		n = len(transactions)
		for i in range(n):
			(n1, t1, a1, d1) = transactions[i].split(',')
			if int(a1) > 1000:
				res.add(transactions[i])
			for j in range(i + 1, n):
				(n0, t0, a0, d0) = transactions[j].split(',')
				if n0 == n1 and d1 != d0 and (abs(int(t1) - int(t0)) <= 60):
					res.add(transactions[i])
					res.add(transactions[j])
		ans = []
		for t in res:
			ans.append(t)
		print(res, ans)
		return ans


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalidTct = []
		for i in range(len(transactions)):
			(name1, time1, amount1, location1) = transactions[i].split(',')
			if int(amount1) > 1000:
				invalidTct.append(transactions[i])
			for j in range(i + 1, len(transactions)):
				(name2, time2, amount2, location2) = transactions[j].split(',')
				if name1 == name2 and abs(int(time1) - int(time2)) <= 60 and (location1 != location2):
					invalidTct.append(transactions[i])
					invalidTct.append(transactions[j])
		return list(set(invalidTct))


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalidSet = set()
		for (i, transaction) in enumerate(transactions):
			(name1, time1, amount1, city1) = transaction.split(',')
			if int(amount1) > 1000:
				invalidSet.add(transaction)
			for j in range(i + 1, len(transactions)):
				(name2, time2, amount2, city2) = transactions[j].split(',')
				if name1 == name2 and abs(int(time2) - int(time1)) <= 60 and (city1 != city2):
					invalidSet.add(transactions[j])
					invalidSet.add(transaction)
		return invalidSet


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		lenth = len(transactions)
		ans = set()
		for i in range(lenth):
			(name, time, price, city) = transactions[i].split(',')
			if int(price) > 1000:
				ans.add(transactions[i])
			for j in range(i, lenth):
				(n_name, n_time, n_price, n_city) = transactions[j].split(',')
				if name == n_name and n_city != city and (abs(int(n_time) - int(time)) <= 60):
					ans.add(transactions[i])
					ans.add(transactions[j])
		return ans


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		temp = []
		for t in transactions:
			temp.append(t.split(','))
		res = []
		for i in range(len(temp)):
			if int(temp[i][2]) > 1000 and ','.join(temp[i]) not in res:
				res.append(','.join(temp[i]))
			for j in range(i + 1, len(temp)):
				if temp[i][0] == temp[j][0] and temp[i][3] != temp[j][3]:
					if abs(int(temp[i][1]) - int(temp[j][1])) <= 60:
						if ','.join(temp[i]) not in res:
							res.append(','.join(temp[i]))
						if ','.join(temp[j]) not in res:
							res.append(','.join(temp[j]))
		return res


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		arr = []
		for x in transactions:
			(n, a, t, p) = x.split(',')
			arr.append([n, a, t, p])
		inv = []
		for i in range(len(arr)):
			(n, t, a, p) = arr[i]
			added = False
			if int(a) > 1000:
				inv.append(arr[i])
				added = True
			for j in range(i + 1, len(arr)):
				(nn, tt, aa, pp) = arr[j]
				if abs(int(t) - int(tt)) <= 60 and n == nn and (p != pp):
					if not added:
						inv.append(arr[i])
						added = True
					inv.append(arr[j])
		inv = [','.join(x) for x in inv]
		inv = list(set(inv))
		return inv


import collections

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		byName = collections.defaultdict(list)
		invalids = set()
		for transaction in transactions:
			(name, t_min, amt, city) = transaction.split(',')
			byName[name].append((int(t_min), int(amt), city, transaction))
			if int(amt) > 1000:
				invalids.add(transaction)
		for name in byName:
			trans = byName[name]
			for i in range(len(trans)):
				for j in range(i, len(trans)):
					if abs(trans[i][0] - trans[j][0]) <= 60 and trans[i][2] != trans[j][2]:
						invalids.add(trans[i][3])
						invalids.add(trans[j][3])
		return list(invalids)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		transactionDict = {}
		invalid = []
		for i in transactions:
			transactionData = i.split(',')
			(name, time, amount, city) = (transactionData[0], transactionData[1], transactionData[2], transactionData[3])
			if name in transactionDict.keys():
				transactionVal = transactionDict[name]
			else:
				transactionVal = []
			transactionVal.append([time, amount, city])
			transactionDict[name] = transactionVal
		for i in transactionDict.keys():
			for v in transactionDict[i]:
				if int(v[1]) > 1000:
					if '{},{},{},{}'.format(i, v[0], v[1], v[2]) not in invalid:
						invalid.append('{},{},{},{}'.format(i, v[0], v[1], v[2]))
				for listd in transactionDict[i]:
					if listd != v:
						if abs(int(v[0]) - int(listd[0])) <= 60 and v[2] != listd[2]:
							if '{},{},{},{}'.format(i, v[0], v[1], v[2]) not in invalid:
								invalid.append('{},{},{},{}'.format(i, v[0], v[1], v[2]))
		return invalid


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalids = set()
		for i in range(len(transactions)):
			(name, time, amount, city) = transactions[i].split(',')
			if int(amount) > 1000:
				invalids.add(transactions[i])
			j = i + 1
			while j < len(transactions):
				(nameJ, timeJ, amountJ, cityJ) = transactions[j].split(',')
				if nameJ == name and abs(int(timeJ) - int(time)) <= 60 and (city != cityJ):
					invalids.add(transactions[i])
					invalids.add(transactions[j])
				j += 1
		return list(invalids)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalidIdxList = set()
		transDict = {}
		for (i, transaction) in enumerate(transactions):
			(name, time, amount, city) = transaction.split(',')
			if int(amount) > 1000:
				invalidIdxList.add(i)
			j = i + 1
			while j < len(transactions):
				(otherName, otherTime, otherAmount, otherCity) = transactions[j].split(',')
				if name == otherName and abs(int(time) - int(otherTime)) <= 60 and (city != otherCity):
					invalidIdxList.add(i)
					invalidIdxList.add(j)
				j = j + 1
		res = []
		for idx in invalidIdxList:
			res.append(transactions[idx])
		return res


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		n = len(transactions)
		invalid_check = [0] * n
		for i in range(n):
			i_info = transactions[i].split(',')
			assert len(i_info) == 4
			if int(i_info[2]) >= 1000:
				invalid_check[i] = 1
			for j in range(i + 1, n):
				j_info = transactions[j].split(',')
				assert len(j_info) == 4
				if i_info[0] == j_info[0] and i_info[3] != j_info[3] and (abs(int(i_info[1]) - int(j_info[1])) <= 60):
					invalid_check[i] = invalid_check[j] = 1
		ret = []
		for i in range(n):
			if invalid_check[i]:
				ret.append(transactions[i])
		return ret


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		ans = []
		num = len(transactions)
		added = set()
		for i in range(num):
			(name1, time1, num1, city1) = transactions[i].split(',')
			if int(num1) > 1000 and i not in added:
				ans.append(transactions[i])
				added.add(i)
			for j in range(i + 1, num):
				(name2, time2, num2, city2) = transactions[j].split(',')
				if name1 == name2 and abs(int(time2) - int(time1)) <= 60 and (city2 != city1):
					if i not in added:
						ans.append(transactions[i])
						added.add(i)
					if j not in added:
						ans.append(transactions[j])
						added.add(j)
		return ans


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		res = set()
		for i in range(len(transactions) - 1):
			t1 = transactions[i].split(',')
			if int(t1[2]) > 1000:
				res.add(transactions[i])
			for j in range(i + 1, len(transactions)):
				t2 = transactions[j].split(',')
				if t1[0] == t2[0] and t1[3] != t2[3] and (abs(int(t2[1]) - int(t1[1])) <= 60):
					res.add(transactions[i])
					res.add(transactions[j])
				if int(t2[2]) > 1000:
					res.add(transactions[j])
		return list(res)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		M = collections.defaultdict(dict)
		ans = set()
		for t in transactions:
			(name, time, amount, city) = t.split(',')
			if int(amount) > 1000:
				ans.add(t)
			Flag = False
			if name in M:
				for (k, v) in list(M[name].items()):
					if abs(int(time) - k) <= 60 and v.split(',')[-1] != city:
						ans.add(v)
						Flag = True
			M[name][int(time)] = t
			if Flag:
				ans.add(t)
		return list(ans)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalid = set()
		for (i, t) in enumerate(transactions):
			(name, time, amount, city) = t.split(',')
			if int(amount) > 1000:
				invalid.add(i)
				continue
			for j in range(len(transactions)):
				if i == j:
					continue
				(jname, jtime, jamount, jcity) = transactions[j].split(',')
				if jname == name and jcity != city and (abs(int(jtime) - int(time)) <= 60):
					invalid.add(i)
					invalid.add(j)
		return [transactions[i] for i in invalid]


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		res = []
		for i in range(len(transactions)):
			added = False
			for j in range(i + 1, len(transactions)):
				a = transactions[i].split(',')
				b = transactions[j].split(',')
				if a[0] == b[0] and a[-1] != b[-1] and (abs(int(a[1]) - int(b[1])) <= 60):
					res.append(','.join(a))
					res.append(','.join(b))
					added = True
			if not added:
				if int(transactions[i].split(',')[2]) > 1000:
					res.append(transactions[i])
		return list(set(res))


class Solution:

	def invalidTransactions(self, ts: List[str]) -> List[str]:
		nts = [t.split(',') for t in ts]
		nts = sorted([[a, int(b), int(c), d] for (a, b, c, d) in nts])
		res = set()
		for a in nts:
			if a[2] > 1000:
				res.add(','.join(map(str, a)))
		for i in range(len(nts)):
			for j in range(i + 1, len(nts)):
				(a, b) = (nts[i], nts[j])
				if a[0] != b[0] or abs(a[1] - b[1]) > 60:
					break
				if a[3] != b[3]:
					res.add(','.join(map(str, a)))
					res.add(','.join(map(str, b)))
		return list(res)


class Transaction:

	def __init__(self, name, time, amount, city):
		self.name = name
		self.time = int(time)
		self.amount = int(amount)
		self.city = city

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		transactions = [Transaction(*t.split(',')) for t in transactions]
		transactions.sort(key=lambda x: x.time)
		nameMap = collections.defaultdict(list)
		for (i, t) in enumerate(transactions):
			nameMap[t.name].append(i)
		invalid = []
		for (name, idxLst) in nameMap.items():
			left = 0
			right = 0
			for idx in idxLst:
				t = transactions[idx]
				if t.amount > 1000:
					invalid.append(f'{t.name},{t.time},{t.amount},{t.city}')
					continue
				while left < len(idxLst) and transactions[idxLst[left]].time < t.time - 60:
					left += 1
				while right < len(idxLst) and transactions[idxLst[right]].time <= t.time + 60:
					right += 1
				for i in range(left, right):
					if t.city != transactions[idxLst[i]].city:
						invalid.append(f'{t.name},{t.time},{t.amount},{t.city}')
						break
		return invalid


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		if not transactions or len(transactions) == 0:
			return []
		d = collections.defaultdict(dict)
		res = set()
		for t in transactions:
			(name, time, amount, city) = t.split(',')
			if int(amount) > 1000:
				res.add(t)
			flag = False
			if name in d:
				for (_time, _t) in d[name].items():
					if abs(_time - int(time)) <= 60 and city != _t.split(',')[-1]:
						flag = True
						res.add(_t)
			if flag:
				res.add(t)
			d[name][int(time)] = t
		return list(res)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalid = []
		for (i, t1) in enumerate(transactions):
			(name1, time1, amount1, city1) = t1.split(',')
			if int(amount1) > 1000:
				invalid.append(t1)
				continue
			for (j, t2) in enumerate(transactions):
				if i != j:
					(name2, time2, amount2, city2) = t2.split(',')
					if name1 == name2 and city1 != city2 and (abs(int(time1) - int(time2)) <= 60):
						invalid.append(t1)
						break
		return invalid


import collections

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalid = []
		mapNameToTrans = collections.defaultdict(list)
		for t in transactions:
			(name, time, amount, city) = t.split(',')
			if int(amount) > 1000:
				invalid.append(t)
				did_add = True
			else:
				did_add = False
			for past in mapNameToTrans[name]:
				if abs(int(past[0]) - int(time)) <= 60 and past[1] != city:
					if not did_add:
						invalid.append(t)
						did_add = True
					if not past[2]:
						past[2] = True
						invalid.append(past[3])
			mapNameToTrans[name].append([time, city, did_add, t])
		return invalid


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		personalTransactions = {}
		invalidTransactions = set()
		for i in transactions:
			(name, time, amount, city) = i.split(',')
			if int(amount) > 1000:
				invalidTransactions.add(i)
			if name not in personalTransactions.keys():
				personalTransactions[name] = [(int(time), city, amount)]
				continue
			else:
				personalTransactions[name].append((int(time), city, amount))
				for j in personalTransactions[name]:
					if city == j[1]:
						continue
					elif abs(j[0] - int(time)) <= 60:
						invalidTransactions.add(i)
						invalidTransactions.add(name + ',' + str(j[0]) + ',' + j[2] + ',' + j[1])
		return list(invalidTransactions)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		transMap = dict()
		invalids = set()
		for t in transactions:
			(name, time, amount, city) = t.split(',')
			if int(amount) > 1000:
				invalids.add(t)
			if name in transMap:
				for (stime, scity, st) in transMap[name]:
					if abs(int(time) - int(stime)) <= 60 and city != scity:
						invalids.add(st)
						invalids.add(t)
			else:
				transMap[name] = []
			transMap[name].append((time, city, t))
		return list(invalids)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		(trans, invalid) = ([], [])
		for t in transactions:
			trans += (t.split(','),)
		trans.sort(key=lambda x: int(x[1]))
		invalid = set()
		for i in range(len(trans)):
			if int(trans[i][2]) > 1000:
				invalid.add(','.join(trans[i]))
				if i:
					j = i
					while j and int(trans[i][1]) - int(trans[j - 1][1]) < 61:
						if trans[i][0] == trans[j - 1][0] and trans[i][3] != trans[j - 1][3]:
							invalid.add(','.join(trans[j - 1]))
						j -= 1
			elif i and int(trans[i][1]) - int(trans[i - 1][1]) < 61:
				j = i
				while j and int(trans[i][1]) - int(trans[j - 1][1]) < 61:
					if trans[i][0] == trans[j - 1][0] and trans[i][3] != trans[j - 1][3]:
						invalid.add(','.join(trans[j - 1]))
						invalid.add(','.join(trans[i]))
					j -= 1
		return invalid


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:

		def giddy(item):
			return item.split(',')
		result = set()
		seen = collections.defaultdict(list)
		transactions = list(map(giddy, transactions))
		for i in range(len(transactions)):
			val = transactions[i]
			if int(val[2]) > 1000:
				result.add(','.join(val))
			if val[0] in seen:
				for x in seen[val[0]]:
					comp = transactions[x]
					if abs(int(comp[1]) - int(val[1])) <= 60 and comp[3] != val[3]:
						result.add(','.join(val))
						result.add(','.join(comp))
			seen[val[0]].append(i)
		return result


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalid_trans = set()
		d = {}
		for transaction in transactions:
			t_list = transaction.split(',')
			(person, time, amount, loc) = (t_list[0], int(t_list[1]), int(t_list[2]), t_list[3])
			if amount > 1000:
				invalid_trans.add(transaction)
			if person not in d:
				d[person] = []
			else:
				for t in d[person]:
					old_t = t.split(',')
					(old_time, old_loc) = (int(old_t[1]), old_t[3])
					if abs(old_time - time) <= 60 and old_loc != loc:
						invalid_trans.add(transaction)
						invalid_trans.add(t)
			d[person].append(transaction)
		return list(invalid_trans)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		if not transactions:
			return []
		invalid = set()
		past_tran = {}
		for transaction in transactions:
			tran = transaction.split(',')
			tran[2] = float(tran[2])
			tran[1] = float(tran[1])
			if tran[2] > 1000:
				invalid.add(transaction)
			if tran[0] in past_tran:
				for other_transaction in past_tran[tran[0]]:
					other_tran = other_transaction.split(',')
					other_tran[1] = float(other_tran[1])
					if other_tran[3] != tran[3] and abs(tran[1] - other_tran[1]) <= 60:
						invalid.add(transaction)
						invalid.add(other_transaction)
				past_tran[tran[0]].append(transaction)
			else:
				past_tran[tran[0]] = [transaction]
		return list(invalid)


import collections

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		invalid = []
		mapNameToTrans = collections.defaultdict(list)
		for t in transactions:
			(name, time, amount, city) = t.split(',')
			did_add = False
			if int(amount) > 1000:
				invalid.append(t)
				did_add = True
			for past in mapNameToTrans[name]:
				(past_name, past_time, past_amount, past_city) = past[0].split(',')
				if past_city != city and abs(int(past_time) - int(time)) <= 60:
					if not did_add:
						invalid.append(t)
						did_add = True
					if not past[1]:
						past[1] = True
						invalid.append(past[0])
			mapNameToTrans[name].append([t, did_add])
		return invalid


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		res = []
		for (i, t1) in enumerate(transactions):
			item = t1.split(',')
			val = int(item[2])
			minute = int(item[1])
			name = item[0]
			city = item[-1]
			if val > 1000:
				res.append(t1)
				continue
			for (j, t2) in enumerate(transactions):
				if i != j:
					item = t2.split(',')
					val2 = int(item[2])
					minute2 = int(item[1])
					name2 = item[0]
					city2 = item[-1]
					if abs(minute2 - minute) <= 60 and name2 == name and (city2 != city):
						res.append(t1)
						break
		return res


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		dic = defaultdict(list)
		ans = set()
		for trans in transactions:
			(name, time, amt, loc) = trans.split(',')
			if int(amt) > 1000:
				ans.add(trans)
			for trans2 in dic[name]:
				other = trans2.split(',')
				if other[3] != loc and abs(int(other[1]) - int(time)) <= 60:
					ans.add(trans)
					ans.add(trans2)
			dic[name].append(trans)
		return ans


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		tr = {}
		invalids = set()
		for t in transactions:
			tl = t.split(',')
			if tl[0] not in tr:
				tr[tl[0]] = [t]
				if int(tl[2]) > 1000:
					invalids.add(t)
			else:
				if int(tl[2]) > 1000:
					invalids.add(t)
				tmp = tr[tl[0]]
				for temp in tmp:
					tempo = temp.split(',')
					if tempo[3] != tl[3]:
						if abs(int(tempo[1]) - int(tl[1])) <= 60:
							invalids.add(t)
							invalids.add(temp)
				tr[tl[0]].append(t)
		return invalids


class Solution:

	def invalidTransactions(self, transactions):
		transactions.sort()
		n = len(transactions)
		result = set()
		for i in range(n):
			(i_name, i_time, i_amount, i_city) = transactions[i].split(',')
			if int(i_amount) > 1000:
				result.add(transactions[i])
			for j in range(i + 1, n):
				(j_name, j_time, j_amount, j_city) = transactions[j].split(',')
				if j_name != i_name:
					break
				if i_city != j_city and abs(int(i_time) - int(j_time)) <= 60:
					result.add(transactions[i])
					result.add(transactions[j])
		return list(result)


from collections import defaultdict

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		transactions.sort(key=lambda t: int(t.split(',')[1]))
		recent = defaultdict(lambda : [])
		result = set()
		for transaction in transactions:
			(name, time, amount, city) = self.parse(transaction)
			if amount > 1000:
				result |= {transaction}
			if name in recent:
				for recent_transaction in recent[name]:
					(_, recent_time, _, recent_city) = self.parse(recent_transaction)
					if time - recent_time <= 60 and recent_city != city:
						result |= {recent_transaction, transaction}
			recent[name] += [transaction]
		return result

	def parse(self, transaction):
		(name, time, amount, city) = transaction.split(',')
		return (name, int(time), int(amount), city)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		if not transactions:
			return []
		res = set()
		names = defaultdict(list)
		(time, amt, city) = ([], [], [])
		for (i, ele) in enumerate(transactions):
			s = ele.split(',')
			names[s[0]] += [(int(s[1]), int(s[2]), s[3], s[0])]
		for (k, v) in list(names.items()):
			v = sorted(v)
			for (i, ele) in enumerate(v):
				(b, c, d, a) = ele
				for (j, ele1) in enumerate(v):
					if i != j:
						(f, g, h, e) = ele1
						if abs(b - f) <= 60 and a == e and (d != h):
							res.add(a + ',' + str(b) + ',' + str(c) + ',' + d)
							res.add(e + ',' + str(f) + ',' + str(g) + ',' + h)
				if c > 1000:
					res.add(a + ',' + str(b) + ',' + str(c) + ',' + d)
		return res


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		ret = set()
		name = []
		time = []
		amount = []
		city = []
		for trans in transactions:
			trans = trans.split(',')
			name.append(trans[0])
			time.append(int(trans[1]))
			amount.append(int(trans[2]))
			city.append(trans[3])
		for i in range(len(transactions)):
			if amount[i] > 1000:
				ret.add(transactions[i])
			for j in range(i + 1, len(transactions)):
				if name[i] == name[j] and abs(time[i] - time[j]) <= 60 and (city[i] != city[j]):
					ret.add(transactions[i])
					ret.add(transactions[j])
		return ret


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		transactions = [string.split(',') for string in transactions]
		(ans, length) = (set(), len(transactions))
		for i in range(length):
			if int(transactions[i][2]) > 1000:
				ans.add(','.join(transactions[i]))
		dct = {}
		for i in range(length):
			(name, time, city) = (transactions[i][0], transactions[i][1], transactions[i][-1])
			if name in dct:
				dct[name].append((time, city))
				dct[name].sort()
			else:
				dct[name] = [(time, city)]
		for (name, time, amt, city) in transactions:
			for (tme, cty) in dct[name]:
				if abs(int(time) - int(tme)) <= 60 and city != cty:
					ans.add(','.join([name, time, amt, city]))
		return list(ans)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		ans = []
		length = len(transactions)
		if not length:
			return ans
		(name, time, money, city) = ([], [], [], [])
		add = [1] * length
		for trans in transactions:
			tran = trans.split(',')
			name.append(tran[0])
			time.append(eval(tran[1]))
			money.append(eval(tran[2]))
			city.append(tran[3])
		for i in range(length):
			if money[i] > 1000:
				add[i] = False
			for j in range(i + 1, length):
				if name[i] == name[j] and abs(time[i] - time[j]) <= 60 and (city[i] != city[j]):
					add[i] = False
					add[j] = False
		for (ind, val) in enumerate(add):
			if not val:
				ans.append(transactions[ind])
		return ans


from collections import defaultdict

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		dic = defaultdict(list)
		res = set()
		for i in transactions:
			i = i.split(',')
			if int(i[2]) > 1000:
				res.add(','.join(i))
			if i[0] in dic:
				for j in dic[i[0]]:
					j = j.split(',')
					if i[3] != j[3] and abs(int(i[1]) - int(j[1])) <= 60:
						res.add(','.join(i))
						res.add(','.join(j))
			dic[i[0]].append(','.join(i))
		print(dic)
		return list(res)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		tf_arr = [True for _ in range(len(transactions))]
		new_transactions = []
		for x in transactions:
			x = x.split(',')
			x[1] = int(x[1])
			x[2] = int(x[2])
			new_transactions.append(x)

		def check(transaction, i, arr):
			if transaction[2] > 1000:
				tf_arr[i] = False
			for (j, e) in enumerate(arr[i + 1:]):
				if transaction[0] == e[0] and transaction[3] != e[3] and (abs(transaction[1] - e[1]) <= 60):
					tf_arr[i] = False
					tf_arr[i + j + 1] = False
		for (i, t) in enumerate(new_transactions):
			check(t, i, new_transactions)
		output = []
		for (i, truth) in enumerate(tf_arr):
			if not truth:
				output.append(transactions[i])
		return output


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		ans = []
		n = len(transactions)
		rank = [True] * n
		name = []
		time = []
		amount = []
		city = []
		for t in transactions:
			num = t.split(',')
			name.append(num[0])
			time.append(num[1])
			amount.append(num[2])
			city.append(num[3])
		for i in range(n):
			if int(amount[i]) > 1000:
				rank[i] = False
			for j in range(i + 1, n):
				if name[i] == name[j] and abs(int(time[i]) - int(time[j])) <= 60 and (city[i] != city[j]):
					rank[i] = False
					rank[j] = False
		for t in range(n):
			if not rank[t]:
				ans.append(transactions[t])
		return ans


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		personDict = dict()
		outSet = set()
		for transaction in transactions:
			(name, time, amount, city) = transaction.split(',')
			if int(amount) > 1000:
				outSet.add(transaction)
			if name in personDict:
				cityDict = personDict[name]
				cityDict[city].append((time, amount))
				for key in cityDict:
					if key != city:
						for pair in cityDict[key]:
							(prevTime, prevAmount) = pair
							timeDiff = abs(int(time) - int(prevTime))
							if timeDiff <= 60:
								outSet.add(transaction)
								outSet.add(','.join([name, prevTime, prevAmount, key]))
			else:
				personDict[name] = defaultdict(list)
				personDict[name][city].append((time, amount))
		return outSet


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		import collections
		if not transactions:
			return []
		memo = collections.defaultdict(list)
		invalid_tran = set()
		for (i, transaction) in enumerate(transactions):
			(name, time, amount, city) = (int(i) if i.isnumeric() else i for i in transaction.split(','))
			if amount > 1000:
				invalid_tran.add(transaction)
			if name in memo:
				for tran in memo[name]:
					(_, prev_time, _, prev_city) = (int(i) if i.isnumeric() else i for i in tran.split(','))
					if abs(time - prev_time) <= 60 and prev_city != city:
						invalid_tran.add(tran)
						invalid_tran.add(transaction)
			memo[name].append(transaction)
		return invalid_tran


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		if not transactions:
			return []
		dic = defaultdict(list)
		invalid = set()
		for i in range(len(transactions)):
			(name, time, amount, city) = (int(i) if i.isnumeric() else i for i in transactions[i].split(','))
			if amount > 1000:
				invalid.add(transactions[i])
			if name in dic:
				for tran in dic[name]:
					(_, prev_time, _, prev_city) = (int(i) if i.isnumeric() else i for i in tran.split(','))
					if prev_city != city and abs(prev_time - time) <= 60:
						invalid.add(tran)
						invalid.add(transactions[i])
			dic[name].append(transactions[i])
		return list(invalid)


class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		splits = [t.split(',') for t in transactions]
		lists = {}
		res = set()
		for (time, p, v, loc, t) in sorted([[int(sp[1]), sp[0], int(sp[2]), sp[3], t] for (sp, t) in zip(splits, transactions)]):
			if v > 1000:
				res.add(t)
			tk = time % 61
			if p not in lists:
				lists[p] = [None] * 61
			lst = lists[p]
			for i in range(61):
				if lst[i] and abs(lst[i][0] - time) <= 60 and (lst[i][1] != loc):
					res.add(t)
					res.add(lists[p][i][2])
			lst[tk] = [time, loc, t]
		return res


class Transactions:

	def __init__(self, name, time, amount, city):
		self.name = name
		self.time = time
		self.amount = amount
		self.city = city

class Solution:

	def invalidTransactions(self, transactions: List[str]) -> List[str]:
		transact = []
		for t in transactions:
			t = t.split(',')
			obj = Transactions(t[0], int(t[1]), int(t[2]), t[3])
			transact.append(obj)
		transact.sort(key=lambda t: t.time)
		invalid = set()
		for i in range(len(transact)):
			first = transact[i]
			if first.amount > 1000:
				invalid.add(self.returnString(first))
			for j in range(i + 1, len(transact)):
				second = transact[j]
				if first.name == second.name and first.city != second.city and (second.time - first.time <= 60):
					invalid.add(self.returnString(first))
					invalid.add(self.returnString(second))
		return list(invalid)

	def returnString(self, first):
		return first.name + ',' + str(first.time) + ',' + str(first.amount) + ',' + first.city