title: Check Possible Sort Array Conditional Swapping Adjacent Allowed
signature: bool checkPossibleSortArrayConditionalSwappingAdjacentAllowed(vector<int> arr, 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(bool actual, bool expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, bool expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, 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({1, 4, 12, 16, 37, 44, 47, 51, 55, 57, 57, 62, 62, 62, 64, 69, 69, 70, 72, 81, 81, 88, 89, 97}, 15, true); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-86, 0, 14, -16, -12, -72, 62, -34, -72, 30, 84, -60, 84, -64, 50, 74, 18, -82, -64, -64, -74, -56, 86, 84, -32, -10, 20, 4, 8, 96, 82, 26, 42}, 18, false); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      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, 1, 1}, 31, true); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({48, 66, 83, 12, 77, 98, 18, 33, 21, 16, 28, 24, 46, 43}, 13, false); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-92, -58, -36, -28, -6, 2, 4, 26, 48, 58, 60, 62, 62, 98}, 10, true); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 1, 0, 1}, 4, true); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({22, 38, 41, 41, 42, 51, 54, 58, 68, 76, 80, 85}, 9, true); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({84, -38, 52, -72, -24, 82, 54, 74, 0}, 8, false); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 1, 1}, 2, true); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({63, 31, 14, 19, 77, 64, 62, 23, 22, 19, 39, 9, 79, 1, 87, 29, 58, 3, 3, 39, 1, 39, 35, 64, 64}, 13, false); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def check_possible_sort_array_conditional_swapping_adjacent_allowed(arr, n):
      for i in range(0, (n - 1)):
          if (arr[i] > arr[(i + 1)]):
              if ((arr[i] - arr[(i + 1)]) == 1):
                  (arr[i], arr[(i + 1)]) = (arr[(i + 1)], arr[i])
              else:
                  return False
      return True
source_cpp: bool check_possible_sort_array_conditional_swapping_adjacent_allowed(vector<int> arr, int n) {
    for ( int i = 0;
    i < n - 1;
    i ++ ) {
      if ( arr [ i ] > arr [ i + 1 ] ) {
        if ( arr [ i ] - arr [ i + 1 ] == 1 ) swap ( arr [ i ], arr [ i + 1 ] );
        else return false;
      }
    }
    return true;
  }