From the course: Get Ready for Your Coding Interview

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Code solution to sample question #3

Code solution to sample question #3

- [Instructor] Here's my solution in code to sample interview question number three with two dimensional array. Let's implement our function right here. The first thing we're going to do in this function is we'll initialize a new variable called n to len of chessboard. And this is just for convenience, so that we have n that's equal to the number of rows that we have as well as the number of columns that we have in this two-dimensional array. And our assumption here was that the number of columns and the number of rows in this 2D array are the same. And we want to use this variable n just for convenience sake, so that we don't have to repeat writing len of chessboard every time we want to use this number. And after that, I'm going to go over each row and count the number of rooks in each row. To do that, I'm going to write for row_i, for row index, in range of n. And this gives us each row index. And in this for…

Contents