Google | Phone Screen | Question | India
Anonymous User
4962

Hi Leetcoders,
Sharing the exact question asked in Google Phone Interview!!

  • Difficulty Level : Medium-Hard
  • Topics : Greedy/Array

Question:

  • You have been given Red,Blue,Green cards each having 36 cards (108 cards in total),
  • Each 36 cards contain cards with number 1-9 and each card appears 4 times, for eg 1 appear 4 times in Red,Blue,Green Cards.
  • 12 cards will be provided to you and you have to analyse whether this is valid configuration or not

Validity condition:

  • 12 cards can be divided into 4 parts each part contains 3 cards,
  • In each part, cards must be of same color
  • Same color cards can be of same values or consecutive values (like, 1,2,3, etc)

Test Cases:

  • Test case 1:
    Lets say we have enum
    Color
    {
    Red,Blue,Green
    }
    Input : {{Red,1},{Red,1},{Red,1},{Red,1},{Blue,1},{Blue,1},{Blue,1},{Blue,1},{Green,1},{Green,1},{Green,1},{Green,1}}
    So we have this configuration,
    Red Cards : 4 {1,1,1,1}
    Blue Cards : 4 {2,2,2,2}
    Green Cards : 4 {4,4,4,4}

  • Output : False (We cannot divide the cards into 4 parts with the validation conditions).

  • Test case 2:
    Input : {{Red,1},{Red,1},{Red,1},{Red,2},{Red,2},{Red,2},{Blue,1},{Blue,2},{Blue,3},{Green,5},{Green,5},{Green,5}}
    Red Cards : 6 {1,1,1,2,2,2}
    Blue Cards : 3 {1,2,3}
    Green Cards : 3 {5,5,5}

  • Output : True (We can divide the cards into 4 parts with the validation conditions).

  • One of the way to divide the cards is:
    [1,1,1] | [2,2,2] | [1,2,3] | [5,5,5]

Comments (13)