Reddit Experience · Apr 2026 · Los Angeles

Is my solution for LC 2069 generally acceptable as a pass in real interviews?

2 replies

Interview Experience

```cpp #include <cstdlib> #include <vector> using namespace std; class Robot { vector<vector<int>> directions = { {0,1}, // up {0,-1}, // down {-1,0}, // left {1,0} // right };

Full Details

cpp #include &lt;cstdlib&gt; #include &lt;vector&gt; using namespace std; class Robot { vector&lt;vector&lt;int&gt;&gt; directions = { {0,1}, // up {0,-1}, // down {-1,0}, // left {1,0} // right }; // starting position is at origin facing east pair&lt;int,int&gt; curPos = {0,0}; pair&lt;int,int&gt; curDir = {directions[3][0], directions[3][1]}; vector&lt;vector&lt;int&gt;&gt; grid; pair&lt;int,int&gt; turnLeft(pair&lt;int,int&gt;&amp; d){ return {-d.second, d.first}; } pair&lt;int,int&gt; turnRight(pair&lt;int,int&gt;&amp; d){ return {d.second, -d.first}; } public: Robot(int width, int height) { grid = vector&lt;vector&lt;int&gt;&gt;(width, vector&lt;int&gt;(height, 0)); } void step(int num) { int R = grid.size(); int C = grid[0].size(); int nx, ny; while (num &gt; 0){ nx = curPos.first + (curDir.first * 1), ny = curPos.second + (curDir.second * 1); while (nx &lt; 0 || nx &gt; R - 1 || ny &lt; 0 || ny &gt; C - 1){ curDir = this-&gt;turnLeft(curDir); nx = curPos.first + (curDir.first * 1), ny = curPos.second + (curDir.second * 1); } curPos.first = nx, curPos.second = ny; num--; } } vector&lt;int&gt; getPos() { return {curPos.first, curPos.second}; } string getDir() { if (curDir == make_pair(0, 1)) return "North"; if (curDir == make_pair(0, -1)) return "South"; if (curDir == make_pair(-1, 0)) return "West"; if (curDir == make_pair(1, 0)) return "East"; return "Unknown"; } }; /** * Your Robot object will be instantiated and called as such: * Robot* obj = new Robot(width, height); * obj-&gt;step(num); * vector&lt;int&gt; param_2 = obj-&gt;getPos(); * string param_3 = obj-&gt;getDir(); */ 119/142 passed. time limit exceeded in extreme cases like very large grids i looked into the non-TLE solutions and it contains so much obscure knowledge that i dont thihk this was worth it my question is if i am asked this question in real interviews -- early round, final round or bar raiser doesnt matter -- can i just go with my solution and move on?

Free preview. Unlock all questions →

Topics

Strings