Amazon Interview Question for SDE-3s


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
0
of 0 vote

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 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can we do like Insertion sort algorithm implementation

- adilhasan801 December 30, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can relate this problem to a strongly connected component in the graph.
Count maximum of all the strongly connected component nodes which are connected to each other.

- Kr.satish123 January 01, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

aster

- aster January 04, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<noscript>alert(1);</noscript>

- aster January 04, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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)

- murtazaarif2k16 January 11, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int maxCardSelection(Object[][] deck) {
int ms = 0;//max selections
/*loop through the card deck*/
for (int i = 0; i < deck.length; i++) {
if (i == 0) {
//just pick the card
ms += 1;
} else {
/*check if the suite or number equals previous card, this is allowed*/
if ((deck[i][0].equals(deck[i - 1][0])) || (deck[i][1].equals(deck[i - 1][1]))) {
ms += 1;
} else {
/*we cannot continue*/
return ms;
}
}
}
return ms;
}

- kirikanjoroge January 28, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

def deckOfCards(cards, pair): # sde 3 amazon

result = []
result.append(pair)
for i in cards:
if i == pair:
continue
pair = result[-1] # get the last item of the list
if i[0] == pair[0] or i[1] == pair[1]:
result.append(i)

return result


cards = [["H", 3], ["H", 4], ["S", 4], ["D", 5], ["D", 1]]
pair = ["H",3]
print(deckOfCards(cards,pair))

- onkar Jaliminche February 02, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{
def deckOfCards(cards, pair): # sde 3 amazon

result = []
result.append(pair)
for i in cards:
if i == pair:
continue
pair = result[-1] # get the last item of the list
if i[0] == pair[0] or i[1] == pair[1]:
result.append(i)

return result


cards = [["H", 3], ["H", 4], ["S", 4], ["D", 5], ["D", 1]]
pair = ["H",3]
print(deckOfCards(cards,pair))
}}

- Onkar Jaliminche February 02, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def deckOfCards(cards, pair): # sde 3 amazon

result = []
result.append(pair)
for i in cards:
if i == pair:
continue
pair = result[-1] # get the last item of the list
if i[0] == pair[0] or i[1] == pair[1]:
result.append(i)

return result


cards = [["H", 3], ["H", 4], ["S", 4], ["D", 5], ["D", 1]]
pair = ["H",3]
print(deckOfCards(cards,pair))

- Onkar Jaliminche February 02, 2021 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More