How do I search for a number in a 2d array sorted left to right and top to bottom?

后端 未结 20 936
暖寄归人
暖寄归人 2020-11-22 13:03

I was recently given this interview question and I\'m curious what a good solution to it would be.

Say I\'m given a 2d array where all the numbers i

20条回答
  •  遥遥无期
    2020-11-22 13:26

    Binary search through the diagonal of the array is the best option. We can find out whether the element is less than or equal to the elements in the diagonal.

提交回复
热议问题