title: Maximum Consecutive Numbers Present Array
signature: int maximumConsecutiveNumbersPresentArray(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(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int 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({3, 5, 9, 24, 28, 31, 49, 54, 67, 85, 86, 94, 97, 97}, 11, 2); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-34, 16, -80, -10, 80, 2, 50, -74, -76, 36, -84, -24, 74, -54, -22, 46, 80, 58, -8, 70, 24, -88, 52, 62, 30, 42, 48, 16, 78, -82, 64, -36, 84, -72}, 29, 1); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 2); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({49, 61, 68, 4, 90, 89, 71, 74, 45, 61, 35, 41, 59}, 11, 2); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-42, -8, 28, 56, 80, 96}, 4, 1); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1}, 17, 2); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({3, 4, 6, 6, 13, 27, 27, 29, 32, 36, 46, 50, 52, 65, 69, 70, 71, 83, 87, 91}, 10, 2); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({64, -76, 28, 6, 56, 18, 32, -50, -20, 18, -26, -90, 32, 50, -18, 98, 84, 40, 50, 88, -70, -6, -24, -44, -96, -58, 48, -78, -14}, 15, 1); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({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}, 15, 1); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({50, 48, 61, 87, 7, 78, 93, 44, 16, 88, 98, 15, 73, 93, 43, 46, 42, 34, 1, 35, 79, 35, 84, 60, 18, 79, 17, 4, 78, 1, 20, 64}, 25, 3); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def maximum_consecutive_numbers_present_array(arr, n):
      S = set()
      for i in range(n):
          S.add(arr[i])
      ans = 0
      for i in range(n):
          if S.__contains__(arr[i]):
              j = arr[i]
              while S.__contains__(j):
                  j += 1
              ans = max(ans, (j - arr[i]))
      return ans
source_cpp: int maximum_consecutive_numbers_present_array(vector<int> arr, int n) {
    unordered_set < int > S;
    for ( int i = 0;
    i < n;
    i ++ ) S . insert ( arr [ i ] );
    int ans = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) {
        int j = arr [ i ];
        while ( S . find ( j ) != S . end ( ) ) j ++;
        ans = max ( ans, j - arr [ i ] );
      }
    }
    return ans;
  }