Flipkart Interview Question for SDE-2s


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 ?

- AJ May 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include "SnakesnLadders.h"
#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;
}

- AJ May 16, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

remember to format dude. It would be more helpful.

- Vib June 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

remember to format dude. It would be more helpful.

- Vib June 14, 2015 | 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