Adobe Interview Question
Software Engineer / Developers1. Use an array representation of 1..100
2. each a[i] contains value (i+1) if no snake or ladder is there
a[i] contains the value > i and the value pointed by the ladder; if a[i] has a ladder starting
a[i] contains value < i; if a[i] is a snake mouth
3. Create the above array depending on the board structure.
4. Generate two random numbers MOD 100 and use them to take a chance
we can implement it by considering each point as a structure which will have the following variables:
struct point{
int x;
int y;
bool ladderstarting;
int ladder_x,ladder_y;
bool snakestaring;
int snake_x,snake_y
};
by using the following data structure we can implement the snake n ladder game easily.
in the main function we can declare an array of size 100 of this structure like this:
point game[100];
then for each n every point we will define it's property.
Hi,
I think it is better to use HashMap (in java) to store only those points of the game which has either snake or ladder at that point. The key of the hashmap will be the number and the value will be the destination. For e.g., if there is a ladder at number 25 which takes the user to number 60, then in the HashMap we can store 25 as key and 60 as value. If there is nothing (neither ladder nor the snake), that number is not included in the HashMap. This saves a lot of space.
Use an array.
- Ashok February 28, 20111. If an index is beginning or end of a snake or a ladder, put the destination number at that location. (number less than index means snake, number greater than index means ladder).
2. All other array indexes can be put 0.