3. Consider this TypeScript code snippet using binary search on answer to find minimum capacity to ship packages within D days:
function canShip(weights: number[], capacity: number, D: number): boolean {
let days = 1, total = 0;
for (const w of weights) {
if (total + w > capacity) {
days++;
total = 0;
}
total += w;
}
return days <= D;
}
function shipWithinDays(weights: number[], D: number): number {
let low = Math.max(...weights);
let high = weights.reduce((a, b) => a + b, 0);
while (low < high) {
const mid = Math.floor((low + high) / 2);
if (canShip(weights, mid, D)) high = mid;
else low = mid + 1;
}
return low;
}
console.log(shipWithinDays([1,2,3,4,5,6,7,8,9,10], 5));What is the output?