Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-10-25_15-28-15.png
49.6 KB
#medium

#N1395. Count Number of Teams
problem link=>https://leetcode.com/problems/count-number-of-teams/

#solution
class Solution {
public int numTeams(int[] rating) {
int res = 0;

for (int i = 1; i < rating.length - 1; ++i) {

int less[] = new int[2], greater[] = new int[2];

for (int j = 0; j < rating.length; ++j) {

if (rating[i] < rating[j])
++less[j > i ? 1 : 0];

if (rating[i] > rating[j])
++greater[j > i ? 1 : 0];
}

res += less[0] * greater[1] + greater[0] * less[1];
}

return res;
}
}