Ledger Lookup
easyAn accountant keeps invoice numbers in a ledger sorted ascending, no duplicates. Given the sorted list ledger and an invoice number invoice, return the index where it appears — or -1 if it was never filed.
Your lookup must run in O(log n): the ledger is long and the accountant is impatient.
Example 1
in ledger = [-1, 0, 3, 5, 9, 12], invoice = 9
out 4
Example 2
in ledger = [-1, 0, 3, 5, 9, 12], invoice = 2
out -1
Constraints
- · 1 <= len(ledger) <= 2000
- · -10^4 <= ledger[i], invoice <= 10^4
- · ledger is strictly increasing
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.