4 ms·
>>"The first round started with introductions, followed by a coding exercise — write a maze solving algorithm. What the fuck?! Seriously?...I am not a recent co
by tyingq 11y ago
>>"The first round started with introductions, followed by a coding exercise — write a maze solving algorithm. What the fuck?! Seriously?...I am not a recent college graduate anymore"
I wonder if just writing a brute-force maze solver, and then explaining that you are aware better solutions exist...but that you didn't have any memorized, would have sufficed.
- akadien 11y agoIf you're sure you don't want the job, turn the tables and say something like "I have no clue. Can you show me?" Most likely, they don't have a clue either.
- jghn 11y agoUnlikely. They have likely asked that question countless times and even if they couldn't initially they could now. If you could go back in time to before they've ever seen it, well then yeah, I agree.
- taneq 11y ago(Edit: Whoops, I misread you and thought you were saying you couldn't remember the brute-force one, not the more elegant solution. Ah what the hell, it was fun to write. :) A recursive implementation of depth-first search should only take ten minutes to write. OK, here, I'll do it without looking anything up. Start time 8:55pm. #include <stdio.h> #include <memory.h> const int WIDTH = 32; // adjust to suit const int HEIGHT = 32; // adjust to suit const bool WALLS[WIDTH][HEIGHT] = { // enter maze layout here, true = wall // this isn't a test of file IO knowledge // make sure the outer perimeter of the maze is // fully closed with walls }; const int START_X = 16; // adjust to suit const int START_Y = 16; // adjust to suit const int GOAL_X = 16; // adjust to suit const int GOAL_Y = 16; // adjust to suit bool search_maze(bool **searched, int cur_x, int cur_y, int start_x, int start_y) { const int DIRS = 4; const int DIR_X = { -1, 0, 1, 0 }; const int DIR_Y = { 0, 1, 0, -1 }; searched[cur_x][cur_y] = true; for (int i=0; i<DIRS; i++) { int new_x = cur_x + DIR_X[i]; int new_y = cur_y + DIR_Y[i]; if (WALLS[new_x][new_y]) continue; // if moving in this direction lands us on the start // point, or searching starting here returns true, // then we're done and our current pos is on the path if ((new_x == start_x && new_y == start_y) || (!searched[new_x][new_y] && search_maze( searched, new_x, new_y, start_x, start_y)) { printf("Go to %d, %d\n", new_x, new_y); return true; } } return false; } int main(int argc, char **argv) { bool searched[WIDTH][HEIGHT]; memset(searched, 0, sizeof(searched)); printf("Starting at %d, %d\n", START_X, START_Y); search_maze(searched, GOAL_X, GOAL_Y, START_X, START_Y); printf("Goal at %d, %d\n", GOAL_X, GOAL_Y); return 0; } End time 9:12pm. So 17 minutes (what's that rule about estimating software dev time?), and I haven't run and tested it yet, but it should show what the interviewer wants.
- Lawtonfogle 11y ago"Being that this isn't my specialty, I would research a solution online as it would provide a far greater business value for the time spent. But you probably want to see me try to solve it anyways, so I let's start with a brute force and improve from there." Point out that in a real life scenario you wouldn't do this because it is so more efficient to use the work of others, but then solve the problem so they can measure your problem solving skills.