package leetcode;

import java.util.List;

/**
 * https://leetcode.com/problems/invalid-transactions/
 */
public class Problem1169 {
    public List<String> invalidTransactions(String[] transactions) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1169 prob = new Problem1169();
        System.out.println(prob.invalidTransactions(new String[]{
            "alice,20,800,mtv","alice,50,100,beijing"})); // ["alice,20,800,mtv","alice,50,100,beijing"]
        System.out.println(prob.invalidTransactions(new String[]{
            "alice,20,800,mtv","alice,50,100,beijing","alice,5,100,beijing"})); // ["alice,20,800,mtv","alice,50,100,beijing","alice,5,100,beijing"]
        System.out.println(prob.invalidTransactions(new String[]{
            "alice,20,800,mtv","alice,50,1200,mtv"})); // ["alice,50,1200,mtv"]
        System.out.println(prob.invalidTransactions(new String[]{
            "alice,20,800,mtv","bob,50,1200,mtv"})); // ["bob,50,1200,mtv"]
        System.out.println(prob.invalidTransactions(new String[]{
            "alice,5,100,beijing","alice,50,100,beijing"})); // []
        System.out.println(prob.invalidTransactions(new String[]{
            "alice,5,100,beijing","alice,50,100,beijing","alice,80,800,mtv"})); // ["alice,50,100,beijing","alice,80,800,mtv"]
    }
}

@@ -33,13 +33,172 @@
 til.
+Array
 List;
+%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.NavigableSet;%0Aimport java.util.Objects;%0Aimport java.util.Set;%0Aimport java.util.TreeSet;
 %0A%0A/*
@@ -366,36 +366,2167 @@
     
-// TODO%0A        return null;
+Set%3CInteger%3E invalid = new HashSet%3C%3E();%0A        TreeSet%3CTransaction%3E set = new TreeSet%3C%3E();%0A        for (int i = 0; i %3C transactions.length; i++) %7B%0A            String%5B%5D t = transactions%5Bi%5D.split(%22,%22);%0A            String name = t%5B0%5D;%0A            int time = Integer.parseInt(t%5B1%5D);%0A            int amount = Integer.parseInt(t%5B2%5D);%0A            String city = t%5B3%5D;%0A            set.add(new Transaction(i, name, time, amount, city));%0A            if (amount %3E 1000) %7B%0A                invalid.add(i);%0A            %7D%0A        %7D%0A        for (Transaction t1 : set) %7B%0A            NavigableSet%3CTransaction%3E within60Mins = set.subSet(%0A                t1, true, /* we only care about t1.time + 60 */%0A                new Transaction(0, %22%22, t1.time + 60, 0, %22%22), true);%0A            for (Transaction t2 : within60Mins) %7B%0A                if (t1.name.equals(t2.name) && !t1.city.equals(t2.city)) %7B%0A                    invalid.add(t1.index);%0A                    invalid.add(t2.index);%0A                %7D%0A            %7D%0A        %7D%0A        List%3CString%3E answer = new ArrayList%3C%3E();%0A        for (int i : invalid) %7B%0A            answer.add(transactions%5Bi%5D);%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static class Transaction implements Comparable%3CTransaction%3E %7B%0A        private final int index;%0A        private final String name;%0A        private final int time;%0A        private final int amount;%0A        private final String city;%0A%0A        public Transaction(int index, String name, int time, int amount, String city) %7B%0A            this.index = index;%0A            this.name = name;%0A            this.time = time;%0A            this.amount = amount;%0A            this.city = city;%0A        %7D%0A%0A        @Override%0A        public int compareTo(Transaction o) %7B%0A            return Integer.compare(time, o.time);%0A        %7D%0A%0A        @Override%0A        public boolean equals(Object o) %7B%0A            if (this == o) return true;%0A            if (o == null %7C%7C getClass() != o.getClass()) return false;%0A            Transaction that = (Transaction) o;%0A            return index == that.index;%0A        %7D%0A%0A        @Override%0A        public int hashCode() %7B%0A            return Objects.hash(index);%0A        %7D
 %0A   

Update problem 1169