Binary search program cause runtime error and failed hidden test cases

The only thing wrong with your second implementation is using size_t. Change it to int, and it ought to work fine.

size_t is an unsigned type. The value of end can be negative when the search is probing the beginning of the array. This invokes undefined behavior in C. In practice, that usually means the value "underflows" and becomes a huge positive number.