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.
Lisa's Workbook
Lisa's Workbook
Sort by
recency
|
912 Discussions
|
Please Login in order to post a comment
My code in JAVA 8
my js code (javascript) O(n)
my js code (javascript) O(n) `
let results = []; let temp = []; let index = 1; for (let j = 0; j < n; ) { if (arr[j] >= k) { arr[j] -= k; temp = [...Array(k + 1).keys()];
} else { temp = [...Array(arr[j] + 1).keys()]; if (index <= 1) { } else { temp = temp.map((value) => value + (index - 1)); } temp.shift();
} } let count = 0; for (let r = 0; r < results.length; r++) { if (results[r].includes(r + 1)) { count++; } }
return count; `
function workbook(n, k, arr) { let superProblems = 0; let currentPage = 1; for(let i = 0; i < n; i++) { let totalQuestionsOnPage = 0; for(let j = 1; j <= arr[i]; j++) { if(totalQuestionsOnPage >= k) { currentPage++; totalQuestionsOnPage = 0; } if(currentPage === j) { superProblems++; } totalQuestionsOnPage++; } currentPage++; totalQuestionsOnPage = 0; } return superProblems; }
javascript