title: Stack Permutations Check If An Array Is Stack Permutation Of Other
signature: function stack_permutations_check_if_an_array_is_stack_permutation_of_other(ip, op, n)
source_py: def stack_permutations_check_if_an_array_is_stack_permutation_of_other(ip, op, n):
      Input = Queue()
      for i in range(n):
          Input.put(ip[i])
      output = Queue()
      for i in range(n):
          output.put(op[i])
      tempStack = []
      while (not Input.empty()):
          ele = Input.queue[0]
          Input.get()
          if (ele == output.queue[0]):
              output.get()
              while (len(tempStack) != 0):
                  if (tempStack[(- 1)] == output.queue[0]):
                      tempStack.pop()
                      output.get()
                  else:
                      break
          else:
              tempStack.append(ele)
      return (Input.empty() and (len(tempStack) == 0))
source_cpp: bool stack_permutations_check_if_an_array_is_stack_permutation_of_other(vector<int> ip, vector<int> op, int n) {
    queue < int > input;
    for ( int i = 0;
    i < n;
    i ++ ) input . push ( ip [ i ] );
    queue < int > output;
    for ( int i = 0;
    i < n;
    i ++ ) output . push ( op [ i ] );
    stack < int > tempStack;
    while ( ! input . empty ( ) ) {
      int ele = input . front ( );
      input . pop ( );
      if ( ele == output . front ( ) ) {
        output . pop ( );
        while ( ! tempStack . empty ( ) ) {
          if ( tempStack . top ( ) == output . front ( ) ) {
            tempStack . pop ( );
            output . pop ( );
          }
          else break;
        }
      }
      else tempStack . push ( ele );
    }
    return ( input . empty ( ) && tempStack . empty ( ) );
  }
question_info.entry_fn_name: stack_permutations_check_if_an_array_is_stack_permutation_of_other
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(ip, op, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(ip, op, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({2, 3, 3, 3, 4, 5, 6, 9, 18, 20, 35, 39, 39, 45, 50, 55, 57, 61, 63, 65, 72, 73, 77, 77, 78, 87, 88, 91, 93, 95, 98}, {2, 5, 7, 13, 16, 23, 24, 25, 27, 31, 31, 33, 34, 35, 38, 46, 49, 49, 51, 52, 58, 61, 62, 66, 68, 71, 73, 78, 91, 94, 98}, 23, false)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-86, 10, -8, 8, -24, -2, -84, -86, -54, 50, 56, -22, -8, -62, 0, -50, -32}, {-8, -46, 22, -66, -94, -96, 70, 58, -4, -70, -96, 34, -80, -26, -52, 52, -76}, 16, false)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, false)
      print(string.format("TEST-2...%s",result))
  
      result = driver({3, 42, 88, 89, 41, 71, 67, 5, 84, 20, 75, 36, 34, 20, 31, 16, 86, 89, 53, 47, 57, 27, 47, 93, 59, 66, 40, 18, 69, 36, 98, 99, 81}, {16, 61, 39, 99, 71, 73, 35, 47, 62, 80, 1, 49, 54, 35, 39, 55, 7, 6, 85, 84, 11, 51, 38, 4, 72, 10, 33, 65, 64, 32, 16, 99, 9}, 19, false)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -94, -94, -90, -88, -82, -80, -78, -78, -68, -58, -58, -52, -36, -30, -14, -12, -6, -2, -2, 2, 4, 10, 14, 22, 24, 26, 38, 38, 46, 46, 48, 50, 54, 58, 60, 64, 64, 66, 70, 74, 74, 86, 88, 96, 96}, {-92, -92, -80, -72, -72, -72, -70, -68, -64, -56, -40, -38, -34, -24, -10, -8, -8, -2, 0, 2, 4, 6, 14, 14, 18, 20, 34, 36, 36, 38, 38, 42, 48, 56, 64, 70, 72, 76, 76, 76, 76, 78, 84, 90, 94, 96}, 27, false)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0}, 19, false)
      print(string.format("TEST-5...%s",result))
  
      result = driver({19, 37, 44, 65, 72, 87}, {17, 31, 39, 46, 56, 88}, 4, false)
      print(string.format("TEST-6...%s",result))
  
      result = driver({88}, {-30}, 0, true)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, 13, false)
      print(string.format("TEST-8...%s",result))
  
      result = driver({5, 8, 53, 60, 85, 94, 77, 53, 81, 54, 67, 48, 56, 49, 16, 1, 85, 6, 55, 98, 62, 36, 4, 7, 64}, {69, 37, 32, 5, 84, 14, 25, 9, 86, 85, 30, 82, 99, 92, 32, 43, 79, 58, 75, 90, 49, 54, 95, 76, 80}, 12, false)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": false, "inputs": {"ip": [2, 3, 3, 3, 4, 5, 6, 9, 18, 20, 35, 39, 39, 45, 50, 55, 57, 61, 63, 65, 72, 73, 77, 77, 78, 87, 88, 91, 93, 95, 98], "op": [2, 5, 7, 13, 16, 23, 24, 25, 27, 31, 31, 33, 34, 35, 38, 46, 49, 49, 51, 52, 58, 61, 62, 66, 68, 71, 73, 78, 91, 94, 98], "n": 23}}, {"idx": 1, "outputs": false, "inputs": {"ip": [-86, 10, -8, 8, -24, -2, -84, -86, -54, 50, 56, -22, -8, -62, 0, -50, -32], "op": [-8, -46, 22, -66, -94, -96, 70, 58, -4, -70, -96, 34, -80, -26, -52, 52, -76], "n": 16}}, {"idx": 2, "outputs": false, "inputs": {"ip": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "op": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 21}}, {"idx": 3, "outputs": false, "inputs": {"ip": [3, 42, 88, 89, 41, 71, 67, 5, 84, 20, 75, 36, 34, 20, 31, 16, 86, 89, 53, 47, 57, 27, 47, 93, 59, 66, 40, 18, 69, 36, 98, 99, 81], "op": [16, 61, 39, 99, 71, 73, 35, 47, 62, 80, 1, 49, 54, 35, 39, 55, 7, 6, 85, 84, 11, 51, 38, 4, 72, 10, 33, 65, 64, 32, 16, 99, 9], "n": 19}}, {"idx": 4, "outputs": false, "inputs": {"ip": [-98, -94, -94, -90, -88, -82, -80, -78, -78, -68, -58, -58, -52, -36, -30, -14, -12, -6, -2, -2, 2, 4, 10, 14, 22, 24, 26, 38, 38, 46, 46, 48, 50, 54, 58, 60, 64, 64, 66, 70, 74, 74, 86, 88, 96, 96], "op": [-92, -92, -80, -72, -72, -72, -70, -68, -64, -56, -40, -38, -34, -24, -10, -8, -8, -2, 0, 2, 4, 6, 14, 14, 18, 20, 34, 36, 36, 38, 38, 42, 48, 56, 64, 70, 72, 76, 76, 76, 76, 78, 84, 90, 94, 96], "n": 27}}, {"idx": 5, "outputs": false, "inputs": {"ip": [1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "op": [0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0], "n": 19}}, {"idx": 6, "outputs": false, "inputs": {"ip": [19, 37, 44, 65, 72, 87], "op": [17, 31, 39, 46, 56, 88], "n": 4}}, {"idx": 7, "outputs": true, "inputs": {"ip": [88], "op": [-30], "n": 0}}, {"idx": 8, "outputs": false, "inputs": {"ip": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], "op": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], "n": 13}}, {"idx": 9, "outputs": false, "inputs": {"ip": [5, 8, 53, 60, 85, 94, 77, 53, 81, 54, 67, 48, 56, 49, 16, 1, 85, 6, 55, 98, 62, 36, 4, 7, 64], "op": [69, 37, 32, 5, 84, 14, 25, 9, 86, 85, 30, 82, 99, 92, 32, 43, 79, 58, 75, 90, 49, 54, 95, 76, 80], "n": 12}}]