title: Maximum Consecutive Numbers Present Array
signature: maximum_consecutive_numbers_present_array <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(3L, 5L, 9L, 24L, 28L, 31L, 49L, 54L, 67L, 85L, 86L, 94L, 97L, 97L), 11L, 
          2L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-34L, 16L, -80L, -10L, 80L, 2L, 50L, -74L, -76L, 36L, -84L, -24L, 74L, -54L, -22L, 46L, 80L, 58L, -8L, 70L, 24L, -88L, 52L, 62L, 30L, 42L, 48L, 16L, 78L, -82L, 64L, -36L, 84L, -72L), 29L, 
          1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 13L, 
          2L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(49L, 61L, 68L, 4L, 90L, 89L, 71L, 74L, 45L, 61L, 35L, 41L, 59L), 11L, 
          2L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-42L, -8L, 28L, 56L, 80L, 96L), 4L, 
          1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L), 17L, 
          2L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 4L, 6L, 6L, 13L, 27L, 27L, 29L, 32L, 36L, 46L, 50L, 52L, 65L, 69L, 70L, 71L, 83L, 87L, 91L), 10L, 
          2L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(64L, -76L, 28L, 6L, 56L, 18L, 32L, -50L, -20L, 18L, -26L, -90L, 32L, 50L, -18L, 98L, 84L, 40L, 50L, 88L, -70L, -6L, -24L, -44L, -96L, -58L, 48L, -78L, -14L), 15L, 
          1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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), 15L, 
          1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(50L, 48L, 61L, 87L, 7L, 78L, 93L, 44L, 16L, 88L, 98L, 15L, 73L, 93L, 43L, 46L, 42L, 34L, 1L, 35L, 79L, 35L, 84L, 60L, 18L, 79L, 17L, 4L, 78L, 1L, 20L, 64L), 25L, 
          3L
      )))
  
  }
  
  main()
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;
  }