#1996

The Number of Weak Characters in the Game

specialist · 945 · lc medium +32 · verified · 44.5% accepted · 3,096 likes · top 27%

Description

In a game, each character has an attack value and a defense value, represented by properties[i] = [attacki, defensei]. A character is considered weak if some other character surpasses it in both attack and defense simultaneously (strictly greater in both dimensions).

Return the total number of weak characters.

Example 1:

Input: properties = [[5,5],[6,3],[3,6]]
Output: 0
Explanation: No character has strictly greater attack and defense than the other.

Example 2:

Input: properties = [[2,2],[3,3]]
Output: 1
Explanation: The first character is weak because the second character has a strictly greater attack and defense.

Example 3:

Input: properties = [[1,5],[10,4],[4,3]]
Output: 1
Explanation: The third character is weak because the second character has a strictly greater attack and defense.

Code

1
2
3