Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Below code reads a maze and and its walls from a text file. The text file contains entire maze in the format of 0's and 1's.
00000000000000000
01111111111101110
01000101000001010
01011101111111010
01010001000101000
01011101011101110
01000101010100000
01011101110101110
01010000010001000
01010111011101110
01010101000001000
01011101111111010
01110100010000010
01110111011111010
00010000000101010
01111111111101010
00000000000000000

While 0's represent wall/obstacles, 1's represent a path. One can define another class for MazeCellType where type can be a path and a wall

private void CreateDungeon() {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(Constants.dungeonFile));
            String line;
            int lineNumber = 0;
            while ((line = reader.readLine()) != null && !line.isEmpty()
                    && lineNumber < this.sizeOfMaze) {
                int columnNumber = 0;
                String[] paths = line.split("0");
                for (int i = 0; i < paths.length; i++) {
                    String path = paths[i];
                    int j = 0;
                    while (j < path.length() && columnNumber < this.sizeOfMaze) {
                        this.dungeon[lineNumber][columnNumber].type = Path;
                        columnNumber++;
                        j++;
                    }
                    if (columnNumber < this.sizeOfMaze) {
                        this.dungeon[lineNumber][columnNumber].type = Wall;
                        columnNumber++;
                    }
                }
                lineNumber++;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception e) {
                    //eat it
                }
            }
        }
    }

- RB July 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If somebody can tell what all possibilities exist for maze.

- cthecool July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Cell
{
public:
       int x;
       int y;
       bool left, right, up, down; // whether it can go left/right/up/down
};

class Maze
{
    std::list<Cell> cells;
};

- xinsikuangchao July 07, 2012 | 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