Sort by

recency

|

952 Discussions

|

  • + 0 comments

    Here is Lisa's Workbook solution in python, java, c++, c and javascript programming - https://programmingoneonone.com/hackerrank-lisas-workbook-problem-solution.html

  • + 0 comments
    public static int workbook(int n, int k, List<Integer> arr) {
    // Write your code here
         Map<Integer, List<Integer>> bookMap = new HashMap<>();
        int pageNr = 1;
    
        for (int i = 0; i < n; i++) {
            List<Integer> problemsPerPage = new ArrayList<>();
            for (int j = 0; j < arr.get(i); j++) {
                if (problemsPerPage.size() == k) {
                    bookMap.put(pageNr, problemsPerPage);
                    pageNr++;
                    problemsPerPage = new ArrayList<>();
                }
                problemsPerPage.add(j + 1);
            }
            bookMap.put(pageNr, problemsPerPage);
            pageNr++;
        }
        AtomicInteger specialProblems = new AtomicInteger();
        bookMap.keySet().forEach(key -> {
            if (bookMap.get(key).contains(key)) {
                specialProblems.getAndIncrement();
            }
        });
    
        return specialProblems.get();
    }
    
  • + 1 comment

    Too many variables? Maybe. Do I care? Absolutely not!

    int workbook(int n, int k, vector<int> arr) {
        int problems = 0;
        int bookMark = 1;
        
        for(int i = 0; i<arr.size(); i++){
            int pages = (arr[i] + k - 1) / k;
            int firs_exe = 1;
            int last_exe = min(firs_exe + k - 1, arr[i]);
            
            while (pages-->0) {
                
                if(firs_exe <= bookMark && bookMark <= last_exe) problems++;    
                
                firs_exe = last_exe + 1;
                last_exe = min(firs_exe + k - 1, arr[i]);
                bookMark++;
            }
        }
        
        return problems;
    }
    
  • + 0 comments

    JAVA

    public static int workbook(int n, int k, List arr)

    {
    int page = 1;
    int count = 0;
    for(int i=0;i<n;i++){
        int noq = arr.get(i);
        int j =1;
        while(j<=noq){
            int ques = j;
            int qcount = 1;
            while(qcount<=k){
                if(ques==page){
                    count++;
                }
                ques++;
                if(ques>noq){
                    break;
                }   
                qcount++;             
            }
            page++;
            j+=k;
        }
        }
        return count;
    }
    
  • + 0 comments
    def workbook(n, k, arr):
        # Write your code here
        
        current_page_no = 0
        special_problem_count = 0
        for chapter in range(1, n+1):
            pages = math.ceil(arr[chapter-1] / k)
            current_problems = 0
            while pages > 0:
                current_page_no += 1
                problems_on_current_page = k if (arr[chapter-1] - current_problems) > k else arr[chapter-1] - current_problems
                if current_page_no > current_problems and current_page_no <= (current_problems+problems_on_current_page):
                    special_problem_count += 1
                current_problems += problems_on_current_page
                pages -= 1            
        return special_problem_count