title: Maximum Removal From Array When Removal Time Waiting Time
signature: class Solution {
  
      public Integer maximumRemovalFromArrayWhenRemovalTimeWaitingTime(ArrayList<Integer> arr, Integer n) {
source_py: def maximum_removal_from_array_when_removal_time_waiting_time(arr, n):
      count = 0
      cummulative_sum = 0
      arr.sort()
      for i in range(n):
          if (arr[i] >= cummulative_sum):
              count += 1
              cummulative_sum += arr[i]
      return count
source_cpp: int maximum_removal_from_array_when_removal_time_waiting_time(vector<int> arr, int n) {
    int count = 0;
    int cummulative_sum = 0;
    sort(arr.begin(), arr.end());
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( arr [ i ] >= cummulative_sum ) {
        count ++;
        cummulative_sum += arr [ i ];
      }
    }
    return count;
  }
question_info.extension: java
question_info.entry_fn_name: maximumRemovalFromArrayWhenRemovalTimeWaitingTime
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 3, "inputs": {"arr": [7, 33, 34, 42, 42, 45, 73], "n": 5}}, {"idx": 1, "outputs": 4, "inputs": {"arr": [-98, -90, -80, -66, -64, -62, -48, -30, -20, -10, 4, 6, 12, 14, 32, 42, 44, 44, 52, 64, 86, 92, 94], "n": 16}}, {"idx": 2, "outputs": 2, "inputs": {"arr": [0, 0, 0, 0, 1], "n": 2}}, {"idx": 3, "outputs": 3, "inputs": {"arr": [11, 44, 71, 82, 85, 89], "n": 3}}, {"idx": 4, "outputs": 5, "inputs": {"arr": [-96, -92, -78, -72, -68, -58, -52, -50, -50, -48, -42, -32, -20, -18, -4, 0, 0, 2, 18, 18, 20, 24, 32, 34, 36, 38, 38, 60, 66, 68, 70, 72, 72, 74, 76, 96, 98], "n": 21}}, {"idx": 5, "outputs": 11, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 16}}, {"idx": 6, "outputs": 5, "inputs": {"arr": [8, 9, 10, 11, 12, 15, 17, 19, 20, 21, 24, 30, 33, 35, 36, 39, 41, 41, 42, 54, 62, 63, 68, 70, 71, 72, 77, 85, 86, 86, 94, 95, 97, 97], "n": 31}}, {"idx": 7, "outputs": 6, "inputs": {"arr": [-94, -90, -72, -70, -66, -60, -24, -16, 4, 4, 10, 22, 28, 36, 46, 60, 70, 72, 76, 92, 96], "n": 20}}, {"idx": 8, "outputs": 13, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 13}}, {"idx": 9, "outputs": 4, "inputs": {"arr": [7, 10, 12, 16, 20, 28, 31, 40, 42, 47, 53, 57, 59, 63, 63, 67, 69, 84, 90, 97], "n": 10}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(7, 33, 34, 42, 42, 45, 73)), 5, 3);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-98, -90, -80, -66, -64, -62, -48, -30, -20, -10, 4, 6, 12, 14, 32, 42, 44, 44, 52, 64, 86, 92, 94)), 16, 4);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 1)), 2, 2);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(11, 44, 71, 82, 85, 89)), 3, 3);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-96, -92, -78, -72, -68, -58, -52, -50, -50, -48, -42, -32, -20, -18, -4, 0, 0, 2, 18, 18, 20, 24, 32, 34, 36, 38, 38, 60, 66, 68, 70, 72, 72, 74, 76, 96, 98)), 21, 5);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 16, 11);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(8, 9, 10, 11, 12, 15, 17, 19, 20, 21, 24, 30, 33, 35, 36, 39, 41, 41, 42, 54, 62, 63, 68, 70, 71, 72, 77, 85, 86, 86, 94, 95, 97, 97)), 31, 5);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-94, -90, -72, -70, -66, -60, -24, -16, 4, 4, 10, 22, 28, 36, 46, 60, 70, 72, 76, 92, 96)), 20, 6);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 13, 13);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(7, 10, 12, 16, 20, 28, 31, 40, 42, 47, 53, 57, 59, 63, 63, 67, 69, 84, 90, 97)), 10, 4);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__