Leetcode 1996 The Number of Weak Characters in the Game Solution in java | Hindi Coding Community



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 ith character in the game.

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.

Return the number of weak characters.

class Solution {
public int numberOfWeakCharacters(int[][] properties) {
int[] maxH = new int[100002];
int count = 0;
for(int[] point:properties){
maxH[point[0]] = Math.max(point[1],maxH[point[0]]);
for(int i=100000;i>=0;i--){
maxH[i] = Math.max(maxH[i+1],maxH[i]);
for(int[] point:properties){
return count;

Post a Comment

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !