A growth dashboard shows week-over-week changes in a grid grid. Each row is sorted from largest to smallest (left to right), and each column is sorted from largest to smallest (top to bottom).
Write countNegative(grid) that returns how many cells hold a negative number. Use O(rows + cols) time.
Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]] Output: 8
The negative cells fill the bottom-right corner: 1 + 1 + 2 + 4 = 8.
Input: grid = [[3,2],[1,0]] Output: 0
0 is not negative.
1 <= rows, cols <= 100-100 <= grid[r][c] <= 100Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #176 Count Negative Deltas. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.