A game editor stores tile IDs of a sprite sheet in a grid sheet. Each row is sorted ascending, and the first ID of each row is bigger than the last ID of the row above, so reading the rows one after another gives one sorted list.
Write inSheet(sheet, target) that returns true if target is one of the IDs and false otherwise.
Use O(log(rows × cols)) time.
Input: sheet = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 16 Output: true
16 is in the middle row.
Input: sheet = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13 Output: false
13 would sit between 11 and 16, but it is not there.
1 <= rows, cols <= 300-10^6 <= sheet[r][c], target <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #163 Find a Tile in a Sprite Sheet. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.