You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.

Return a list answer of size 2 where:


	answer[0] is a list of all players that have not lost any matches.
	answer[1] is a list of all players that have lost exactly one match.


The values in the two lists should be returned in increasing order.

Note:


	You should only consider the players that have played at least one match.
	The testcases will be generated such that no two matches will have the same outcome.


&nbsp;
Example 1:

Input: matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]
Output: [[1,2,10],[4,5,7,8]]
Explanation:
Players 1, 2, and 10 have not lost any matches.
Players 4, 5, 7, and 8 each have lost one match.
Players 3, 6, and 9 each have lost two matches.
Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].


Example 2:

Input: matches = [[2,3],[1,3],[5,4],[6,4]]
Output: [[1,2,5,6],[]]
Explanation:
Players 1, 2, 5, and 6 have not lost any matches.
Players 3 and 4 each have lost two matches.
Thus, answer[0] = [1,2,5,6] and answer[1] = [].


&nbsp;
Constraints:


	1 &lt;= matches.length &lt;= 105
	matches[i].length == 2
	1 &lt;= winneri, loseri &lt;= 105
	winneri != loseri
	All matches[i] are unique.


class Solution:
    def findWinners(self, matches: List[List[int]]) -> List[List[int]]:
        winners, losers, table = [], [], {}
        for winner, loser in matches:
            # map[key] = map.get(key, 0) + change . This format ensures that KEY NOT FOUND error is always prevented.
            # map.get(key, 0) returns map[key] if key exists and 0 if it does not.
            table[winner] = table.get(winner, 0) # Winner
            table[loser] = table.get(loser, 0) + 1
        for k, v in table.items(): # Player k with losses v
            if v == 0:
                winners.append(k) # If player k has no loss ie v == 0
            if v == 1:
                losers.append(k) # If player k has one loss ie v == 1
        return [sorted(winners), sorted(losers)] # Problem asked to return sorted arrays.
class Solution {
    public List<List<Integer>> findWinners(int[][] matches) {
        int[] won = new int[100001];
        int[] loss = new int[100001];
        
        for(int[] match : matches) {
            won[match[0]]++;
            loss[match[1]]++;
        }
        
        // System.out.print(Arrays.toString(won));
        // System.out.print(Arrays.toString(loss));
        
        List<List<Integer>> ans  = new ArrayList<>();
        
        List<Integer> wonAllMatches = new ArrayList<>();
        List<Integer> lostOneMatch = new ArrayList<>();
        
        for(int i = 0; i < won.length; i++) {
            if(won[i] > 0 && loss[i] == 0) { //for checking players that have not lost any match.
                wonAllMatches.add(i);
            }
            
            if(loss[i] == 1) {
                lostOneMatch.add(i); //for checking players that have lost exactly one match.
            }
        }
        
        ans.add(wonAllMatches);
        ans.add(lostOneMatch);
        
        return ans;
    }
}
class Solution {
public:
    vector<vector<int>> findWinners(vector<vector<int>>& matches) {
        unordered_map<int,int> umap;
        vector<vector<int>> result(2);
        for(int i=0;i<matches.size();i++)
        {
            umap[matches[i][1]]++;
        }
        for(auto i=umap.begin();i!=umap.end();i++)
        {
            if(i->second==1)
            {
                result[1].push_back(i->first);
            }
        }
        for(int i=0;i<matches.size();i++)
        {
            if(umap[matches[i][0]]==0)
            {
                result[0].push_back(matches[i][0]);
                umap[matches[i][0]]=1;
            }
        }

        sort(result[0].begin(),result[0].end());

        sort(result[1].begin(),result[1].end());

        return result;
    }
};
/**
 * @param {number[][]} matches
 * @return {number[][]}
 */
var findWinners = function(matches) {
    var looser = {};
    var allPlayer={};
    for(var i=0; i<matches.length; i++)
        {
            if(looser[matches[i][1]])
                looser[matches[i][1]]++;
            else
                looser[matches[i][1]]=1

            if(!allPlayer[matches[i][0]])
                allPlayer[matches[i][0]]=1
            if(!allPlayer[matches[i][1]])
                allPlayer[matches[i][1]]=1
        }
    var first=[], second=[];
    for(var key in allPlayer)
        {
            if(!looser[key])
                first.push(key);
            if(looser[key] == 1)
                second.push(key);
        }
    return [first, second]
};
Find Players With Zero or One Losses