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 #4

Code solution to sample question #4

- Let's see what my Lea time solution might look like and could. The problem was counting the number of negative numbers in a two-dimensional array, in which each column and each row are already sorted. Let's implement our function right here. At the beginning of this function we'll initialize a new variable called, "Count to zero." And we're going to use this variable to keep track of the number of negative numbers we've seen so far. And then we're going to use two variables: "row_i" for row index and "col_i" for column index to keep track of which number we're examining currently. And since the first number that we're going to examine is the number at the top right corner, so we're going to initialize row_i to zero and col_i to length of given array. Square brackets zero, minus one, since we'll start at the last column of this array. After that, we're going to run a while loop with while col_i is larger…

Contents