title: Check If X Can Give Change To Every Person In The Queue
signature: check_if_x_can_give_change_to_every_person_in_the_queue <- function(notes, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(notes, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(notes, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(5L, 5L, 5L, 10L, 20L), 4L, 
          1L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(5L, 5L, 5L, 20L, 10L), 5L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L), 27L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 18L), 12L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(5L, 5L, 20L), 2L, 
          1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(10L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), 17L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(5L, 10L, 20L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), 7L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-82L, -10L, -78L, -84L, 68L, 62L, 10L, 20L, -86L, -98L, 92L, 70L, 40L, -12L, -20L, -36L, 8L, -70L, 6L, 8L, 44L, -24L, 8L, -18L, 76L, -54L, -14L, -94L, -68L, -62L, -24L, -36L, -74L, 92L, 92L, -80L, 48L, 56L, 94L), 31L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), 25L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(46L, 46L, 93L, 57L, 82L, 34L, 83L, 80L, 77L, 36L, 80L, 85L, 69L, 28L, 9L, 56L, 49L, 27L, 83L, 25L, 1L, 80L, 99L, 14L, 69L, 82L, 79L, 71L, 74L, 34L), 20L, 
          0L
      )))
  
  }
  
  main()
source_py: def check_if_x_can_give_change_to_every_person_in_the_queue(notes, n):
      fiveCount = 0
      tenCount = 0
      for i in range(n):
          if (notes[i] == 5):
              fiveCount += 1
          elif (notes[i] == 10):
              if (fiveCount > 0):
                  fiveCount -= 1
                  tenCount += 1
              else:
                  return 0
          elif ((fiveCount > 0) and (tenCount > 0)):
              fiveCount -= 1
              tenCount -= 1
          elif (fiveCount >= 3):
              fiveCount -= 3
          else:
              return 0
      return 1
source_cpp: int check_if_x_can_give_change_to_every_person_in_the_queue(vector<int> notes, int n) {
    int fiveCount = 0;
    int tenCount = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( notes [ i ] == 5 ) fiveCount ++;
      else if ( notes [ i ] == 10 ) {
        if ( fiveCount > 0 ) {
          fiveCount --;
          tenCount ++;
        }
        else return 0;
      }
      else {
        if ( fiveCount > 0 && tenCount > 0 ) {
          fiveCount --;
          tenCount --;
        }
        else if ( fiveCount >= 3 ) {
          fiveCount -= 3;
        }
        else return 0;
      }
    }
    return 1;
  }