We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Can anyone helps me? I only use one for loop but there 's still runtime error. Thank you:((
int flatlandSpaceStations(int n, int c_count, int* c) {
/int res = 0;
if (c_count == 1) return max(c_count-1, n-1-c_count);
qsort(c, c_count, sizeof(int), cmp);
int temp = 0;
for (int i = 0; i < c_count-1; i++){
temp = (c[i+1] - c[i])/2;
if (temp > res) res = temp;
}
res = max(max(c[0], n-1-c[c_count-1]), res);
return res;/
int res = 0, f_idx = 1e9;
int dem[n]; for (int i = 0; i < n; i++) dem[i] = 0;
for (int i = 0; i < c_count; i++) {
if (c[i] < f_idx) f_idx = c[i];
dem[c[i]] = 1;
}
int temp = 0, p_idx = f_idx;
for (int i = 0; i < n; i++){
if (dem[i]){
temp = (i-p_idx)/2;
p_idx = i;
}
if (temp > res) res = temp;
}
res = max(max(f_idx, n-1-p_idx), res);
return res;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Flatland Space Stations
You are viewing a single comment's thread. Return to all comments →
Can anyone helps me? I only use one for loop but there 's still runtime error. Thank you:(( int flatlandSpaceStations(int n, int c_count, int* c) { /int res = 0; if (c_count == 1) return max(c_count-1, n-1-c_count); qsort(c, c_count, sizeof(int), cmp); int temp = 0; for (int i = 0; i < c_count-1; i++){ temp = (c[i+1] - c[i])/2; if (temp > res) res = temp; } res = max(max(c[0], n-1-c[c_count-1]), res); return res;/
}