Program to find Kth Smallest Element in a Sorted Matrix
class Solution(object):
def kthSmallest(self, matrix, k):
count=0
ksml=0
for i in range(len(matrix)):
if(len(matrix[i])>0):
for j in range(len(matrix[i])):
count+=1
if(count==k):
ksml=matrix[i][j]
break
print ksml
lst= [[ 1, 5, 9],[10, 11, 13], [12, 13, 15]]
obj=Solution()
obj.kthSmallest(lst,8)
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment