## Amazon Interview Question

SDE-3s**Country:**United States

**Interview Type:**Phone Interview

```
let pairs = [["S", 3], ["H", 4], ["S", 4], ["D", 5], ["D", 1],["S",5]]
function findPair(pair, index, sequence) {
let suit = pair[0]
let snum = pair[1]
for (let n = 0; n < pairs.length; n++) {
if (n == index) continue
const ipair = pairs[n];
let isuit = ipair[0]
let isnum = ipair[1]
if (sequence[isuit + "_" + isnum]) continue
if (suit == isuit) {
sequence[isuit + "_" + isnum] = true
findPair(ipair, n, sequence)
}
if (snum == isnum) {
sequence[isuit + "_" + isnum] = true
findPair(ipair, n, sequence)
}
}
return sequence
}
const element = pairs[0];
let sequence = {}
sequence[element[0] + "_" + element[1]] = true
let s= findPair(element, 0, sequence)
console.log(Object.keys(s).length)
```

I think we can solve this problem with the same logic used for longest increasing subsequence. Consider the cards as an array and for each of the other cards see if we can add the current card to our hand. We can add it to our hand if the suit is the same or the value of the card is the same, compare the longest sequence of the current card to the longest sequence of the other card + 1.

- Ricky Betson December 28, 2020