• + 0 comments

    Python3, but iterates over all problems N = sum(arr), so it's O(N). I belive it can be done much better

    def workbook(n, k, arr):
        page_index = 1
        page_count = k
        special_count = 0
        for problems in arr:
            for problem_index in range(1, problems+1):
                if problem_index == page_index:
                    special_count += 1
                page_count -= 1
                if page_count == 0:
                    page_index += 1
                    page_count = k
            if page_count != k:
                page_count = k
                page_index += 1
        return special_count