What are the odds you write a binary search that you'll use more than once instead of just running it and writing down the result?

I have an object representing piecewise linear functions, defined by a sequence of (x_i, y_i) tuples. It has a method to evaluate y for a given value of x. The first step is to find the least i for which x_i is greater than or equal to x: this uses a binary search. Initially, I stored the x values in a separate array and used dotnet's inbuilt Array.BinarySearch. Later I removed this array to save on memory and it now runs a handbuilt binary search on the first items of the array of points instead.

I once needed to write binary search for a microcontroller in C (no libraries). The routine ran about every hour, with appx 4M data points.

I once worked lots of projects in C, microcontrollers, embedded systems etc. It was a start up.

Every time I needed to write something algorithmically demanding, I could do it in a day or two. Im not into Leetcoding, or competitive coding.

Most regular everyday programmers can work these things out in one or two workdays.

Its definitely not like the competitive programmers say, like if you aren't into this full time, at the time you need to write something you won't have access to time, internet and even an IDE and have to write the code in a Google doc(which needs internet connection, when I pointed this out in the interviews they didn't like it).

That's a very surprising angle of questioning. Are you writing some sort of compile-time-only programs?

About 100%?

When do you write code that doesn't need to search? (Unless you hand it all to the database, in which case... sure, you're good)

[deleted]