Matrix - 2: Find number of elements lesser than or equal to given value in Sorted Matrix

preview_player
Показать описание
Solution:
- We start from 1st row & last column of matrix
- We take a count variable, which'll store the number of element lesser or equal to given value in matrix,
- If value is greater or equal than current matrix value, it means, all left values are smaller than value, so we add column + 1 in count. After it, we increase the row.
- If value is less than current matrix value, we go in previous column
- We do this until, row is less than last row & column is greater of equal to 1st column
- At last, we return count

Time Complexity: O(n + m)
Space Complexity: O(1)

Do Watch video for more info

CHECK OUT CODING SIMPLIFIED

★☆★ VIEW THE BLOG POST: ★☆★

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ Send us mail at: ★☆★
Рекомендации по теме
Комментарии
Автор

count value in case of 20 should be 1. We see 8 as count in the first example.

alisheheryar