## Interview Question

**Country:**United States

The question is to find out a pair of integers in the integer array, which meets the special condition, but not the sum of a pair of integers. So, you need to have a pair of indexes to keep track when the max_val is updated. Also, the second condition shall be less or equal instead of less.

Why the answer is not { 120, 125 } ?

{{

func main() {

arr := []int{90, 85, 75, 60, 120, 150, 125}

integer := 250

heap := generateHeapOfPairs(integer, arr)

fmt.Println("All pairs", heap.ToArray())

if !heap.IsEmpty() {

fmt.Println("Largest Pair", heap.RootElement().ToString())

}

}

func generateHeapOfPairs(limit int, arr []int) minMaxHeap.Heap {

length := len(arr)

pairs := make([]minMaxHeap.Comparable, 0, length*length)

for i := 0; i < length; i++ {

for j := 0; j < length; j++ {

p := Pair{arr[i], arr[j]}

if j > i && p.Sum() < limit {

pairs = append(pairs, p)

}

}

}

return minMaxHeap.NewMaxHeap(pairs)

}

}}

Solution 2 - Why the answer is not { 120, 125 } ?

```
func main() {
arr := []int{90, 85, 75, 60, 120, 150, 125}
integer := 250
maxPair := getLargestPair(integer, arr)
fmt.Println("getLargestPair", maxPair)
}
func getLargestPair(limit int, arr []int) Pair {
length := len(arr)
max := Pair{0, 0}
for i := 0; i < length; i++ {
for j := 0; j < length; j++ {
p := Pair{arr[i], arr[j]}
if j > i && p.Sum() < limit && p.Sum() > max.Sum() {
max = p
}
}
}
return max
}
```

1. Generate all possible pairs and compare their sum with some max_value variable. Keep updating the max_value variable till it satisfies our criteria of sum < given integer but max than max_value. Time complexity O(n^2)

2. Sort the list. Traverse list from both end and compare the sum with given integers. Increase left side if you sum becomes less than given integer else decrease right side.

- gsharma34065 July 13, 2019