Iam_Sandeep

Median in a row-wise sorted Matrix

Jun 14th, 2022
1,474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. #User function Template for python3
  2. from bisect import bisect_right as br
  3. class Solution:
  4.     def median(self, mat, r, c):
  5.         count=(r*c)>>1
  6.         l,r=1,16
  7.         while l<=r:
  8.             m=(l+r)>>1
  9.            
  10.             p=0
  11.             for i in mat:
  12.                 j=br(i,m)
  13.                 p=p+j
  14.             if p<=count:
  15.                 l=m+1
  16.             else:
  17.                 r=m-1
  18.         return l
  19.        
Advertisement
Add Comment
Please, Sign In to add comment