Dsa
Recursion
Hard
The Sierpinski Coordinate Path
A Sierpinski Triangle of level $N$ is built in a 2D plane. Level 0 is a single point at $(0,0)$. At level $n$, we move from the current center to one of three directions: 'T' (Top), 'L' (Left), or 'R' (Right). The distance of the move is $2^{n-1}$. 'T' moves $y$ by $+d$, 'L' moves $x$ by $-d$ and $y$ by $-d$, 'R' moves $x$ by $+d$ and $y$ by $-d$. Given $N$ and a path of length $N$ (e.g., 'TLR'), find the final $(x, y)$ coordinates. Example: $N=1$, Path='T' -> $(0, 1)$. $N=2$, Path='TL' -> $(-1, 1)$.
Key concepts
recursiongeometryfractals
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now