Analysis: multiple for-loops still in constant time
This is an interesting problem: the key here is to keep track of the frequency within the Y, frequency outside of the Y, and then at this point we can try "all possibilities". But all possibilities here means actually a constant time. In the code below, you have 3*3*3 = 27 iterations. Just be careful when you see nested loops, they may still be cnstant time. Code is down below, cheers, ACC. Minimum Operations to Write the Letter Y on a Grid - LeetCode You are given a 0-indexed n x n grid where n is odd, and grid[r][c] is 0 , 1 , or 2 . We say that a cell belongs to the Letter Y if it belongs to one of the following: The diagonal starting at the top-left cell and ending at the center cell of the grid. The diagonal starting at the top-right cell and ending at the center cell of the grid. The vertical line starting at the center cell and ending at the bottom border of the grid. The Letter Y is written on the grid if and only if: All values at cells belonging to th