Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
540 views
in Interview-Experiences by Expert (30,360 points) | 540 views

1 Answer

0 like 0 dislike
Google Phone Interview

Partition cards in sequences
We use cards numbered from 1-9.
valid sequence = three cards with consecutive numbers. E.g.234
invalid sequence = 256

 

The player has 12 cards, and wins if there exists a partition of them that forms 4 sequences.
Write a function that takes in a list of 12 numbers and decides whether or not it forms a winning hand.
//Can use a number only once
Input 1 : [ 1, 4, 3, 2, 5, 7, 8, 6, 9, 3, 2, 4]
//Sequences: 123, 456, 789, 234
o/p: True
input 2 [ 1, 4, 4, 2, 5, 7, 8, 6, 9, 3, 2, 4]
//Sequences: 123, 456, 789, (invalid)244
o/p: False
by Expert (30,360 points)