Skip to main content

Command Palette

Search for a command to run...

Leetcode .1996

Published
•1 min read•View as Markdown

PROBLEM LINK -> https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/

Approach

  1. sort given 2d array in descending order

    qsort(properties, propertiesSize, sizeof(properties[0]), compare);
    
  2. Then we will traverse the 2d array if while traversing the 2d array attack will remain same or it will go on decreasing so we have no problem with attack record so to maintain defense record we will save max defense value in some variable

    int i, weak = 0, maxDefense = 0;
       for (i = 0; i < propertiesSize; i++) {
         if (maxDefense > properties[i][1])
           weak++;
         else
           maxDefense = properties[i][1];
       }