Ctrl K
Problem

Slot on a Sorted Shelf

Easy · Slot on a Sorted Shelf

An archive shelf holds folders whose codes are listed in the array `shelf` in strictly increasing order, with no repeats. A folder with code `code` arrives. If a folder with that code is already on the shelf, return its index. Otherwise return the index where it should be placed so the shelf stays sorted (every folder from that point on shifts one place to the right). Indices are 0-based. Your algorithm should run in O(log n) time.…

Solve the problem →