title: Check If X Can Give Change To Every Person In The Queue
signature: int checkIfXCanGiveChangeToEveryPersonInTheQueue(vector<int> notes, int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> notes, int n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(notes, n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({5, 5, 5, 10, 20}, 4, 1); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({5, 5, 5, 20, 10}, 5, 0); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, 27, 1); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 18}, 12, 0); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({5, 5, 20}, 2, 1); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 17, 0); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({5, 10, 20, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 7, 0); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-82, -10, -78, -84, 68, 62, 10, 20, -86, -98, 92, 70, 40, -12, -20, -36, 8, -70, 6, 8, 44, -24, 8, -18, 76, -54, -14, -94, -68, -62, -24, -36, -74, 92, 92, -80, 48, 56, 94}, 31, 0); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 25, 0); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({46, 46, 93, 57, 82, 34, 83, 80, 77, 36, 80, 85, 69, 28, 9, 56, 49, 27, 83, 25, 1, 80, 99, 14, 69, 82, 79, 71, 74, 34}, 20, 0); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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;
  }