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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Lisa's Workbook
  5. Discussions

Lisa's Workbook

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 879 Discussions, By:

recency

Please Login in order to post a comment

  • sdyadav7049
    10 hours ago+ 0 comments

    please debug my code

     public static int workbook(int n, int k, List<Integer> arr) {
        // Write your code here
            int count=0;
            int pageNo=1;
            for(int i=0;i<arr.size();i++){
                for(int j=0;j<arr.get(i);j++){
                    if(j+1==pageNo){
                        count++;
                    }
                    if((j+1)%k==0||j==arr.size()-1)
                    pageNo++;
                }
            }
            return count;
    
        }
    
    0|
    Permalink
  • 13740mohammad
    1 day ago+ 0 comments
    var page = 1;
    var result = 0;
    for (int i = 0; i < n; i++)
    {
        var index = 1;
        while (index <= arr[i])
        {
            if (page == index)
                result++;
            if (index % k == 0 && index != arr[i])
                page++;
            index++;
        }
        page++;
    }
    return result;
    
    0|
    Permalink
  • himanshu_w9
    2 days ago+ 0 comments

    python 3 solution

    def workbook(n, k, arr): # Write your code here count = 0 p = 1 for i in range(len(arr)): sp = 1 cp = 0 q = math.ceil(arr[i] / k) if k <= arr[i]: cp += k else: cp = arr[i] for j in range(1,q+1): if p <= cp and p >= sp: count += 1 print(sp,cp,p,count) if cp+k <= arr[i]: cp += k else: cp = arr[i] sp += k p += 1 return count

    0|
    Permalink
  • alban_tyrex
    3 weeks ago+ 0 comments

    Here is my c++ solution , you can watch the explanation here : https://youtu.be/3L-haDbsjAg

    int workbook(int n, int k, vector<int> arr) {
        int page = 1, chapter = 1, fe = 1, res = 0;
        while(chapter <= arr.size()){
            int le = min(fe + k - 1, arr[chapter-1]);
            if(fe <= page && page <= le) res++;
            fe = le + 1;
            if(fe > arr[chapter-1]) {
                chapter++;
                fe = 1;
            }
            page ++;
        }   
        return res;
    }
    
    0|
    Permalink
  • kakarlasusritha
    3 weeks ago+ 0 comments
    int workbook(int n, int k, vector<int> arr) {
        int page = 0, special = 0;
        for (int i = 0; i < n; i++) {
            int cur = 0, prev = 0; //cur -> last problem in current page. prev -> last problem in previous page.
            while(arr[i] > 0) {
                prev = cur;
                if (arr[i] > k) 
                    cur += k;  //if arr[i] > k  then k no: of problems are there in current page.
                else 
                    cur += arr[i]; //else only arr[i] no:of problems are there in this page.
                page++; // no: of problems are calculated and page is incremented
                if (page <= cur && page > prev) 
                    special++; //if page no: lies between previous page last problem(exclusive) and current page last problem(inclusive) it is a special problem.
                arr[i] -= k;
            }
        }
        return special;
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy