title: Maximum Possible Sum Window Array Elements Window Array Unique
signature: maximum_possible_sum_window_array_elements_window_array_unique <- function(a, b, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, b, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, b, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(4L, 8L, 10L, 10L, 16L, 23L, 33L, 36L, 43L, 47L, 50L, 55L, 56L, 72L, 84L, 85L, 86L, 86L, 88L, 90L, 92L, 99L), list(8L, 26L, 30L, 35L, 45L, 47L, 55L, 56L, 59L, 61L, 64L, 66L, 67L, 69L, 73L, 77L, 78L, 81L, 82L, 85L, 86L, 99L), 20L, 
          852L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(48L, -22L, 84L, 76L, 50L, -14L, -82L, 28L, 86L, -50L, -40L, 10L, 48L, 20L, -48L, -84L, -64L, -48L, -32L, -84L, -32L, 10L, 42L, -10L, -68L, -16L, -94L, -76L, 42L, -96L, 16L, -64L, 60L, 8L, -88L, -62L, 82L, -24L, -28L, 40L, 18L, 8L), list(82L, 94L, 34L, 12L, 18L, -68L, 14L, -16L, -30L, -16L, 6L, 74L, -68L, 76L, -76L, 52L, -32L, -38L, 78L, 64L, -60L, -46L, 82L, -60L, 98L, -70L, -52L, -96L, -6L, -44L, 66L, -66L, 22L, -42L, -66L, 4L, -2L, -48L, -94L, 72L, 56L, 88L), 30L, 
          240L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 1L), list(0L, 0L, 1L, 1L), 2L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(74L, 64L, 93L, 72L, 75L, 90L, 46L, 72L, 91L, 98L, 57L, 58L, 76L, 29L, 88L, 3L, 86L, 1L, 78L, 74L, 56L, 54L, 57L, 3L, 94L, 2L, 14L, 32L, 67L, 62L, 1L, 30L, 78L, 95L, 40L), list(9L, 50L, 22L, 60L, 36L, 46L, 76L, 48L, 90L, 64L, 16L, 24L, 41L, 12L, 36L, 36L, 93L, 52L, 26L, 38L, 68L, 5L, 55L, 19L, 35L, 5L, 7L, 96L, 67L, 64L, 24L, 85L, 6L, 33L, 7L), 20L, 
          734L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-94L, -88L, -68L, -24L, 60L, 94L), list(-80L, -72L, -60L, -42L, -24L, -6L), 4L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L), list(1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L), 22L, 
          2L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 7L, 12L, 15L, 17L, 23L, 31L, 31L, 32L, 37L, 41L, 54L, 57L, 60L, 62L, 62L, 64L, 70L, 71L, 74L, 75L, 83L, 97L, 98L), list(3L, 10L, 10L, 12L, 12L, 14L, 15L, 19L, 19L, 20L, 25L, 27L, 27L, 28L, 40L, 41L, 50L, 51L, 53L, 57L, 60L, 65L, 75L, 99L), 22L, 
          377L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-2L, 26L, -74L, 96L, -70L, 56L, 92L, -74L, -38L, -18L, 36L, 44L, -10L, -26L, 26L, -22L, -58L, 78L, 86L, 22L, 76L, 50L, 88L, -86L, -80L, -36L, -48L, 90L, -34L, 62L, 46L, -56L, -32L), list(76L, 42L, 0L, 4L, -96L, -24L, -50L, -54L, 26L, -8L, -38L, -46L, 42L, -50L, 16L, -2L, -6L, 2L, -8L, 56L, 64L, -58L, -96L, 2L, -64L, -66L, -14L, 58L, -76L, -26L, 78L, -96L, 48L), 17L, 
          122L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L), list(0L, 0L, 0L, 0L, 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, 1L, 1L, 1L, 1L, 1L), 39L, 
          1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(86L, 30L, 87L, 99L, 8L, 1L, 24L, 46L, 12L, 21L, 43L, 73L, 28L, 3L, 35L, 49L, 14L, 37L, 63L, 98L, 65L, 43L, 86L, 69L, 27L, 60L, 45L, 88L, 25L, 86L, 11L, 9L, 86L, 73L, 40L, 70L, 49L, 50L, 95L, 69L, 94L), list(27L, 66L, 77L, 34L, 98L, 75L, 43L, 27L, 79L, 32L, 54L, 40L, 29L, 47L, 63L, 15L, 23L, 33L, 59L, 76L, 27L, 31L, 92L, 43L, 12L, 20L, 97L, 67L, 11L, 12L, 83L, 79L, 52L, 46L, 51L, 36L, 87L, 96L, 90L, 6L, 62L), 34L, 
          1024L
      )))
  
  }
  
  main()
source_py: def maximum_possible_sum_window_array_elements_window_array_unique(A, B, n):
      mp = set()
      result = 0
      curr_sum = curr_begin = 0
      for i in range(0, n):
          while (A[i] in mp):
              mp.remove(A[curr_begin])
              curr_sum -= B[curr_begin]
              curr_begin += 1
          mp.add(A[i])
          curr_sum += B[i]
          result = max(result, curr_sum)
      return result
source_cpp: int maximum_possible_sum_window_array_elements_window_array_unique(vector<int> A, vector<int> B, int n) {
    unordered_set < int > mp;
    int result = 0;
    int curr_sum = 0, curr_begin = 0;
    for ( int i = 0;
    i < n;
    ++ i ) {
      while ( mp . find ( A [ i ] ) != mp . end ( ) ) {
        mp . erase ( A [ curr_begin ] );
        curr_sum -= B [ curr_begin ];
        curr_begin ++;
      }
      mp . insert ( A [ i ] );
      curr_sum += B [ i ];
      result = max ( result, curr_sum );
    }
    return result;
  }