Google Interview Question
Software EngineersCountry: United States
Interview Type: In-Person
#include<iostream>
using namespace std;
int main() {
bool pack[4][13] = {{0,0}};
bool play=false;
int pack_type=0,number = 0,cnt=0;
cout<<"\nEnter pack_type (1-spade, 2-diamond, 3-heart, 4-club (0 for break):"; cin>>pack_type;
cout<<"Enter number (Ace-1, 2-2,3-3..., J-11, Q-12, K-13 (0 for break):"; cin>> number;
while (pack_type !=0 && number !=0) {
if(pack_type <1 || pack_type>4 || number<1 ||number >13)
return -1;
if (pack[pack_type-1][number-1]==true) {
cout<<"Dup entry";
return -1;
}
pack[pack_type-1][number-1]=true;
cnt++;
cout<<"\nEnter pack_type (1-spade, 2-diamond, 3-heart, 4-club (0 for break):"; cin>>pack_type;
cout<<"Enter number (Ace-1, 2-2,3-3..., J-11, Q-12, K-13 (0 for break):"; cin>> number;
}
if(cnt<3) cout<<"Can't play!!";
for(int i=0;i<4;i++) {
for (int j=0;j<11;j++) {
if (pack[i][j] && pack[i][j+1] && pack[i][j+2]) {
cout<<"Trace1: I can continue to play!!";
printf("Combo :\n %d->%d \n %d->%d \n%d->%d \n",i+1,j+1,i+1,j+2,i+1,j+3);
play=true;
break;
}
}
if(play) {
return 0;
}
}
for(int i=0;i<2;i++) {
for (int j=0;j<13;j++) {
if(pack[i][j] &&pack[i+1][j] &&pack[i+2][j]) {
cout<<"Trace 2:I can continue to play!!";
printf("Combo :\n %d->%d \n %d->%d \n%d->%d \n",i+1,j+1,i+2,j+1,i+3,j+1);
play=true;
break;
}
}
if(play) {
return 0;
}
}
for(int i=0;i<4;i++) {
for (int j=0;j<11;j++) {
cout<<pack[i][j];
}
cout<<'\n';
}
cout<<"I cannot continue to play!!";
return -1;
}
Looking for interview experience sharing and coaching?
- acoding167 July 12, 2019Visit aonecode.com for private lessons by FB, Google and Uber senior engineers
Our ONE TO ONE class offers
SYSTEM DESIGN Courses (highly recommended for candidates for FLAG & U)
ALGORITHMS (conquer DP, Greedy, Graph, Advanced Algos & Clean Coding),
latest interview questions sorted by companies,
mock interviews.
Our students got hired from Google, Facebook, Amazon, LinkedIn and other top tier companies after weeks of training.