function binarySearch(lists, sorted, low, high, target) {
if (low > high) return;
const mid = low + Math.floor((high - low) / 2);
if (sorted[mid] === target) {
lists.push(mid);
}
binarySearch(lists, sorted, low, mid - 1, target);
binarySearch(lists, sorted, mid + 1, high, target);
}
var targetIndices = function (nums, target) {
let result = [];
nums.sort((a, b) => a - b);
if (!nums.includes(target)) return [];
binarySearch(result, nums, 0, nums.length - 1, target);
return result.sort((a, b) => a - b);
};
var targetIndices = function (nums, target) {
nums.sort((a, b) => a - b);
const arr = [];
let start = 0;
let end = nums.length - 1;
while (start <= end) {
const mid = start + Math.floor((end - start) / 2);
if (nums[mid] === target) {
arr.push(mid);
}
if (nums[mid] < target) {
start = mid + 1;
} else {
end = mid - 1;
}
}
return arr.sort((a, b) => a - b);
};
const arr = input.map(Number).sort((a, b) => a - b);
let max = Math.max(...arr);
let min = 1;
while (min <= max) {
let mid = parseInt((max + min) / 2);
let count = arr
.map((line) => parseInt(line / mid))
.reduce((a, b) => a + b, 0);
if (count >= K) {
min = mid + 1;
} else {
max = mid - 1;
}
}
console.log(max);