title: Stack Permutations Check If An Array Is Stack Permutation Of Other
signature: stack_permutations_check_if_an_array_is_stack_permutation_of_other <- function(ip, op, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(ip, op, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(ip, op, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 3L, 3L, 3L, 4L, 5L, 6L, 9L, 18L, 20L, 35L, 39L, 39L, 45L, 50L, 55L, 57L, 61L, 63L, 65L, 72L, 73L, 77L, 77L, 78L, 87L, 88L, 91L, 93L, 95L, 98L), list(2L, 5L, 7L, 13L, 16L, 23L, 24L, 25L, 27L, 31L, 31L, 33L, 34L, 35L, 38L, 46L, 49L, 49L, 51L, 52L, 58L, 61L, 62L, 66L, 68L, 71L, 73L, 78L, 91L, 94L, 98L), 23L, 
          FALSE
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-86L, 10L, -8L, 8L, -24L, -2L, -84L, -86L, -54L, 50L, 56L, -22L, -8L, -62L, 0L, -50L, -32L), list(-8L, -46L, 22L, -66L, -94L, -96L, 70L, 58L, -4L, -70L, -96L, 34L, -80L, -26L, -52L, 52L, -76L), 16L, 
          FALSE
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 
          FALSE
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(3L, 42L, 88L, 89L, 41L, 71L, 67L, 5L, 84L, 20L, 75L, 36L, 34L, 20L, 31L, 16L, 86L, 89L, 53L, 47L, 57L, 27L, 47L, 93L, 59L, 66L, 40L, 18L, 69L, 36L, 98L, 99L, 81L), list(16L, 61L, 39L, 99L, 71L, 73L, 35L, 47L, 62L, 80L, 1L, 49L, 54L, 35L, 39L, 55L, 7L, 6L, 85L, 84L, 11L, 51L, 38L, 4L, 72L, 10L, 33L, 65L, 64L, 32L, 16L, 99L, 9L), 19L, 
          FALSE
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -94L, -94L, -90L, -88L, -82L, -80L, -78L, -78L, -68L, -58L, -58L, -52L, -36L, -30L, -14L, -12L, -6L, -2L, -2L, 2L, 4L, 10L, 14L, 22L, 24L, 26L, 38L, 38L, 46L, 46L, 48L, 50L, 54L, 58L, 60L, 64L, 64L, 66L, 70L, 74L, 74L, 86L, 88L, 96L, 96L), list(-92L, -92L, -80L, -72L, -72L, -72L, -70L, -68L, -64L, -56L, -40L, -38L, -34L, -24L, -10L, -8L, -8L, -2L, 0L, 2L, 4L, 6L, 14L, 14L, 18L, 20L, 34L, 36L, 36L, 38L, 38L, 42L, 48L, 56L, 64L, 70L, 72L, 76L, 76L, 76L, 76L, 78L, 84L, 90L, 94L, 96L), 27L, 
          FALSE
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L), list(0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L), 19L, 
          FALSE
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(19L, 37L, 44L, 65L, 72L, 87L), list(17L, 31L, 39L, 46L, 56L, 88L), 4L, 
          FALSE
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(88L), list(-30L), 0L, 
          TRUE
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L), 13L, 
          FALSE
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(5L, 8L, 53L, 60L, 85L, 94L, 77L, 53L, 81L, 54L, 67L, 48L, 56L, 49L, 16L, 1L, 85L, 6L, 55L, 98L, 62L, 36L, 4L, 7L, 64L), list(69L, 37L, 32L, 5L, 84L, 14L, 25L, 9L, 86L, 85L, 30L, 82L, 99L, 92L, 32L, 43L, 79L, 58L, 75L, 90L, 49L, 54L, 95L, 76L, 80L), 12L, 
          FALSE
      )))
  
  }
  
  main()
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 ( ) );
  }