Smallest missing consecutive number.

Guys, today I have a question that could be useful in many contexts. Let's assume a table with 10 rows and a column [index] that contains a natural number.

As expected, these numbers should go from 1 to 10, so each row will be numbered sequentially:

Row 1: 1

Row 2: 2

Row 3: 3

...

Row 10: 10

However, suppose I delete row 4, leaving 9 rows.

I want to add row 4 back and need a way to calculate that missing 4. One option (valid but from the caveman era) is to create a table with a list of numbers from 1 to whatever, all consecutive, and then filter to find the missing number. But I won't do that because it's inefficient. I believe there should be a more efficient way to achieve this.

The method should find the smallest missing consecutive number. Has anyone done this?

 

1 7 199
7 REPLIES 7
Top Labels in this Space