## Flipkart Interview Question for SDE-2s

• 0

Country: India
Interview Type: In-Person

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

In design rounds, full working code was expected or class diagrams ?

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

#include<math.h>
#define MAX_PLAYERS 4
#define MAX_BLOCK 100
class Player
{
int id;
std::basic_string<char> name;
int position;
public:
Player(int id,std::basic_string<char> name)
{
this->id = id;
this->name = name;

}
int throw_dice()
{
return random()%6;
}

Player(const Player &p)
{
this->id = p.id;
this->name = p.name;
}
int get_position()
{return position;}
void set_position(int n)
{
position = n;
}
};

class Board
{
int n;//no of blocks 100 common case
int move[];

public:
Board()
{
n = MAX_BLOCK;
for(int i =0;i<n;i++)
{
move[i] = -1;

}
}

Board(int n , int move[])
{
this->n = n;
for(int i =0;i<n;i++)
{
this->move[i] = move[i];

}

}
int get_steps()
{
return n;
}
int* get_moves()
{
return move;
}
};

class Game
{
Player players[MAX_PLAYERS];
Board board;
int n;

public: Game(Player p[],Board b,int n);
int play();

};
Game :: Game(Player p[],Board b,int n)
{
this-> n = n;
for(int i = 0;i<n;i++)
this->players[i](&p[i])
this->board = board;

}

int Game::play()
{
int chance = 0;
int dice_value = 0;
while(1)
{
dice_value = players[chance].throw_dice();
int move = 0;
int new_position = players[chance].get_position() + dice_value;
if(move = board.get_moves()[new_position] != -1)
{
new_position += move;
}

if(new_position <= 100)
{
players[chance].set_position(new_position);
}
if(new_position == 100)
return chance;
if(dice_value != 6)
chance = chance == 5 ? 0 : chance+1;

}
return -1;
}

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

remember to format dude. It would be more helpful.

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

remember to format dude. It would be more helpful.

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.

### 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.