You are viewing a single comment's thread. Return to all comments →
Typescript / Javascript solution:
function workbook(n: number, k: number, arr: number[]): number { let usedPages = 0; let specialCount = 0; for (let i = 0; i < arr.length; i++) { const numOfQuestions = arr[i]; const pagesNeeded = Math.ceil(numOfQuestions / k); for (let j = 0; j < pagesNeeded; j++) { const pageNum = usedPages + j + 1; const startIndex = j * k + 1; const endIndex = Math.min(startIndex + k - 1, numOfQuestions); if (pageNum >= startIndex && pageNum <= endIndex) { specialCount++; } } usedPages += pagesNeeded; } return specialCount; }
Seems like cookies are disabled on this browser, please enable them to open this website
Lisa's Workbook
You are viewing a single comment's thread. Return to all comments →
Typescript / Javascript solution: