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.
int workbook(int n, int k, vector arr) {
vector> pages;
int specialCount = 0;
for (int chapter = 0; chapter < n; chapter++) {
int problems = arr[chapter];
int problemNum = 1;
while (problemNum <= problems) {
int end = min(problemNum + k - 1, problems);
vector<int> page;
for (int i = problemNum; i <= end; i++) {
page.push_back(i);
}
pages.push_back(page);
problemNum = end + 1;
}
}
for (int i = 0; i < pages.size(); i++) {
int pageNumber = i + 1;
for (int j=0;j<pages[i].size();j++) {
if (pages[i][j] == pageNumber) {
specialCount++;
}
}
}
return specialCount;
}
Cookie support is required to access HackerRank
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 →
Here is my c++ solution
int workbook(int n, int k, vector arr) { vector> pages; int specialCount = 0;
}