Kth smallest element in sorted matrix

后端 未结 9 2211
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 14:43

This is an interview question.

Find the Kth smallest element in a matrix with sorted rows and columns.
Is it correct that the Kth small

9条回答
  •  星月不相逢
    2020-12-23 15:19

    Above solution could not handle diagonal condition and can not be applied to below matrix

    int arr2[][] = { { 1, 4, 7, 11, 15 }, 
                     { 2, 5, 8, 12, 19 }, 
                     { 3, 6, 9, 16, 22 }, 
                     { 10, 13, 14, 17, 24 },
                     { 18, 21, 23, 26, 30 } }
    

    And k=5

    Returning 7 whereas answer is 5

提交回复
热议问题