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

后端 未结 20 746
暖寄归人
暖寄归人 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

    EDIT:

    I misunderstood the question. As the comments point out this only works in the more restricted case.

    In a language like C that stores data in row-major order, simply treat it as a 1D array of size n * m and use a binary search.

提交回复
热议问题