1996. The Number of Weak Characters in the Game Medium

@problem@discussion
#Array#Stack#Greedy#Sorting#Monotonic Stack



1/**
2 * [1996] The Number of Weak Characters in the Game
3 *
4 * You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] represents the properties of the i^th character in the game.
5 * A character is said to be weak if any other character has both attack and defense levels strictly greater than this character's attack and defense levels. More formally, a character i is said to be weak if there exists another character j where attackj > attacki and defensej > defensei.
6 * Return the number of weak characters.
7 *  
8 * Example 1:
9 * 
10 * Input: properties = [[5,5],[6,3],[3,6]]
11 * Output: 0
12 * Explanation: No character has strictly greater attack and defense than the other.
13 * 
14 * Example 2:
15 * 
16 * Input: properties = [[2,2],[3,3]]
17 * Output: 1
18 * Explanation: The first character is weak because the second character has a strictly greater attack and defense.
19 * 
20 * Example 3:
21 * 
22 * Input: properties = [[1,5],[10,4],[4,3]]
23 * Output: 1
24 * Explanation: The third character is weak because the second character has a strictly greater attack and defense.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	2 <= properties.length <= 10^5
30 * 	properties[i].length == 2
31 * 	1 <= attacki, defensei <= 10^5
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/
37// discuss: https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn number_of_weak_characters(properties: Vec<Vec<i32>>) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_1996() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.