package leetcode;

/**
 * https://leetcode.com/problems/find-the-winner-of-an-array-game/
 */
public class Problem1535 {
    public int getWinner(int[] arr, int k) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1535 prob = new Problem1535();
        System.out.println(prob.getWinner(new int[]{2,1,3,5,4,6,7}, 2)); // 5
        System.out.println(prob.getWinner(new int[]{3,2,1}, 10)); // 3
        System.out.println(prob.getWinner(new int[]{1,9,8,2,3,7,6,4,5}, 7)); // 9
        System.out.println(prob.getWinner(new int[]{1,11,22,33,44,55,66,77,88,99}, 1000000000)); // 99
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -220,32 +220,981 @@
     
-// TODO%0A        return 0
+int answer;%0A        int first = 0;%0A        int last = arr.length - 1;%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        while (true) %7B%0A            int second = (first + 1) %25 arr.length;%0A            if (arr%5Bfirst%5D %3E arr%5Bsecond%5D) %7B%0A                int count = map.getOrDefault(arr%5Bfirst%5D, 0) + 1;%0A                if (count == k) %7B%0A                    answer = arr%5Bfirst%5D;%0A                    break;%0A                %7D%0A                map.put(arr%5Bfirst%5D, count);%0A                int tmp = arr%5Bsecond%5D;%0A                arr%5Bsecond%5D = arr%5Bfirst%5D;%0A                arr%5Bfirst%5D = tmp;%0A            %7D else %7B%0A                int count = map.getOrDefault(arr%5Bsecond%5D, 0) + 1;%0A                if (count == k) %7B%0A                    answer = arr%5Bfirst%5D;%0A                    break;%0A                %7D%0A                map.put(arr%5Bsecond%5D, count);%0A%0A            %7D%0A            first = (first + 1) %25 arr.length;%0A            last = (last + 1) %25 arr.length;%0A        %7D%0A        return answer
 ;%0A  
@@ -1285,24 +1285,26 @@
 blem1535();%0A
+//
         Syst
@@ -1369,16 +1369,18 @@
 ); // 5%0A
+//
         
@@ -1442,16 +1442,18 @@
 ); // 3%0A
+//
         

Update problem 1535