Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

​

Solution: Search in a Sorted Infinite Array

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 2 years ago

import math import sys class Solution: def searchInfiniteSortedArray(self, reader, key): # figure out the reader size by doing binary search between 0 and the # largest integer possible = sys.maxsize def find_array_last_index(): b, e = 0, sys.maxsize index = 0 while b <= e: m = (b + e) // 2 if reader.get(m) == math.inf: e = m - 1 else: b = m + 1 index = m return index # do a binary search to find the first occurrence of the key def search(length): b, e = 0, length index = -1 while b <= e: m = (b + e) // 2 if reader.get(m) >= key: index = m e = m - 1 else: b = m + 1 return index if reade
A

Anonymous

· 3 years ago

Hi,

I get "Unable to execute code." message when running any solution. Please fix it.

Thanks

A

Anonymous

· 4 years ago

Can anyone tell this is which leetcode problem?

Show 1 reply

Reading Progress

0%


Vote for new content