package leetcode;

/**
 * https://leetcode.com/problems/count-number-of-teams/
 */
public class Problem1395 {
    public int numTeams(int[] rating) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1395 prob = new Problem1395();
        System.out.println(prob.numTeams(new int[]{2,5,3,4,1})); // 3
        System.out.println(prob.numTeams(new int[]{2,1,3})); // 0
        System.out.println(prob.numTeams(new int[]{1,2,3,4})); // 4
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -152,16 +152,24 @@
 numTeams
+Backward
 (int%5B%5D r
@@ -189,32 +189,871 @@
     
-// TODO%0A        return 0
+int answer = 0;%0A        for (int i = 0; i %3C rating.length; i++) %7B%0A            answer += numTeams(rating, i, i, 1);%0A        %7D%0A        int%5B%5D reversed = new int%5Brating.length%5D;%0A        for (int i = rating.length - 1, j = 0; i %3E= 0; i--, j++) %7B%0A            reversed%5Bj%5D = rating%5Bi%5D;%0A        %7D%0A        for (int i = 0; i %3C reversed.length; i++) %7B%0A            answer += numTeams(reversed, i, i, 1);%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static int numTeams(int%5B%5D rating, int i, int j, int count) %7B%0A        if (count == 3) %7B%0A            return 1;%0A        %7D%0A        if (j == rating.length) %7B%0A            return 0;%0A        %7D%0A        if (rating%5Bi%5D %3C rating%5Bj%5D) %7B%0A            int a = numTeams(rating, i, j + 1, count);%0A            int b = numTeams(rating, j, j + 1, count + 1);%0A            return a + b;%0A        %7D%0A        return numTeams(rating, i, j + 1, count)
 ;%0A  
@@ -1180,32 +1180,40 @@
 ln(prob.numTeams
+Backward
 (new int%5B%5D%7B2,5,3
@@ -1258,32 +1258,40 @@
 ln(prob.numTeams
+Backward
 (new int%5B%5D%7B2,1,3
@@ -1340,16 +1340,24 @@
 numTeams
+Backward
 (new int

Update problem 1395