#include <stdio.h>

int main() {
    int data[5] = {1, 2, 4, 8, 9};
    int target = 3;
    int low = 1;
    int high = 8;
    int result = -1;

    while (low <= high) {
        int mid = (low + high) / 2;
        int count = 1;
        int installed = data[0];
        for (int i = 1; i < 5; i++) {
            if (data[i]-installed >= mid) {
                count++; 
                installed = data[i];
            } 
        }
        if(count >= mid){
            result = mid;
            low = mid + 1;
        }else{
            high = mid - 1;
        }
    }
    printf("%d ",result);
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: