<p>A transaction is possibly invalid if:</p>

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

<p>You are given an array of strings <code>transaction</code> where <code>transactions[i]</code> consists of comma-separated values representing the name, time (in minutes), amount, and city of the transaction.</p>

<p>Return a list of <code>transactions</code> that are possibly invalid. You may return the answer in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> transactions = [&quot;alice,20,800,mtv&quot;,&quot;alice,50,100,beijing&quot;]
<strong>Output:</strong> [&quot;alice,20,800,mtv&quot;,&quot;alice,50,100,beijing&quot;]
<strong>Explanation:</strong> 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.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> transactions = [&quot;alice,20,800,mtv&quot;,&quot;alice,50,1200,mtv&quot;]
<strong>Output:</strong> [&quot;alice,50,1200,mtv&quot;]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> transactions = [&quot;alice,20,800,mtv&quot;,&quot;bob,50,1200,mtv&quot;]
<strong>Output:</strong> [&quot;bob,50,1200,mtv&quot;]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>transactions.length &lt;= 1000</code></li>
	<li>Each <code>transactions[i]</code> takes the form <code>&quot;{name},{time},{amount},{city}&quot;</code></li>
	<li>Each <code>{name}</code> and <code>{city}</code> consist of lowercase English letters, and have lengths between <code>1</code> and <code>10</code>.</li>
	<li>Each <code>{time}</code> consist of digits, and represent an integer between <code>0</code> and <code>1000</code>.</li>
	<li>Each <code>{amount}</code> consist of digits, and represent an integer between <code>0</code> and <code>2000</code>.</li>
</ul>

class Solution:
    def invalidTransactions(self, transactions: List[str]) -> List[str]:
        invalid_transactions = []
        past_transactions = {}
        
        for item in transactions:
            this_item = Transactions(item)

            if self.check_transaction_amount(this_item):
                print(f'added {this_item.og_string} amount fraud')
                self.add_item_list(this_item,invalid_transactions)
                
            if this_item.name in past_transactions: 
                past_items = past_transactions[this_item.name]
                    
                for past_item in past_items:
                    time_fraud = self.check_transaction_city(past_item,this_item)
                    if time_fraud:
                        print(f'added {this_item.og_string} time fraud')
                        self.add_item_list(past_item,invalid_transactions)
                        self.add_item_list(this_item,invalid_transactions)
                        
                past_transactions[this_item.name].append(this_item)
            else:
                past_transactions[this_item.name] = [this_item]
                
        return invalid_transactions
                
                    
    def check_transaction_city(self,A,B):
        assert (A.name == B.name), 'name filter failed'
        if A.city==B.city:
            return False
        
        if abs(A.time_I - B.time_I) > 60:
            return False
        
        return True
    
    def check_transaction_amount(self,A):
        return A.amount_I > 1000
    
    def add_item_list(self,item,this_list):
        if False == item.added_to_list:
            item.added_to_list = True
            this_list.append(item.og_string)
            
    # def write_string(self,this_item):
    #     this_str = ','.join()
    #     return this_str
                
                
                
class Transactions:
    def __init__(self,item):
        self.name,self.time,self.amount,self.city = item.split(',')
        self.og_string = item
        self.time_I = int(self.time)
        self.amount_I = int(self.amount)
        self.added_to_list = False
112