Skip to content

Latest commit

 

History

History

2225-FindPlayersWithZeroorOneLosses

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Find Players With Zero or One Losses]

Problem can be found in here!

Solution: Counting Sort

def findWinners(matches: List[List[int]]) -> List[List[int]]:
    losses = [-1] * 100001

    for winner, loser in matches:
        if losses[winner] == -1:
            losses[winner] = 0
        if losses[loser] == -1:
            losses[loser] = 1
        else:
            losses[loser] += 1

    answer = [[], []]
    for index, loss in enumerate(losses):
        if loss == 0:
            answer[0].append(index)
        elif loss == 1:
            answer[1].append(index)

    return answer

Time Complexity: O(n+k), Space Complexity: O(k), where n is the size of the input array matches, and k is the range of values in winner or loser.