Skip to the code
cf.
+10 XP

#181 End of the Loaded Rows

easy

A data grid fills its rows as they load. rows holds the loaded row IDs first, followed only by null placeholders for rows that have not loaded yet, such as [8, 3, 5, null, null].

Write loadedCount(rows) that returns how many rows have loaded: the index of the first null, or rows.length if there is no null.

Most of the time only a few rows have loaded in a very long grid, so find the boundary by doubling an index from the start, then binary searching.

Example 1

Input: rows = [8,3,5,null,null]
Output: 3

Three rows have loaded before the first null.

Example 2

Input: rows = [null,null,null]
Output: 0

Nothing has loaded yet.

Constraints

  • 0 <= rows.length <= 100000
  • Every null comes after every loaded row.
Saved in this browser

Run 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).