Skip to content
Programmingoneonone
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

HackerRank Lisa’s Workbook problem solution

YASH PAL, 31 July 2024

In this HackerRank Lisa’s Workbook problem You will be given the details for Lisa’s workbook, can you count its number of special problems?

HackerRank Lisa's Workbook problem solution

Topics we are covering

Toggle
  • Problem solution in Python programming.
  • Problem solution in Java Programming.
    • Problem solution in C++ programming.
    • Problem solution in C programming.
    • Problem solution in JavaScript programming.

Problem solution in Python programming.

if __name__ == '__main__':
    import sys
    n, k = map(int, sys.stdin.readline().strip().split())
    t = list(map(int, sys.stdin.readline().strip().split()))

    page = 0
    n_special = 0
    # Iterate over chapter
    for i in range(n):
        #print("chapter{}".format(i + 1))
        page += 1
        #print("page{}".format(page))
        # Iterate over problems in chapter
        for j in range(1, t[i] + 1):
            #print("tproblem{}".format(j))
            if j == page:
                n_special += 1
            if j != 0 and j % k == 0 and j < t[i]:
                page += 1
                #print("page{}".format(page))

    #print("---")
    print(n_special)

Problem solution in Java Programming.

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int max = in.nextInt();
        int[] arr = new int[num];
        int numPages = 0;
        int curPage = 1;
        int count = 0;
        for(int i =0;i<num;i++){
            arr[i] = in.nextInt();
            for(int prob= 1;prob<=arr[i];prob++){
                int whatPage = prob/max;    
                if(prob == curPage) {
                    count++;
                    //System.out.println("HI chap"+(i+1)+" prob "+prob);
                }
                if(prob%max==0 && prob!=arr[i]){                    
                    curPage++;
                }               
            }      
            //System.out.println("END CHA"+curPage);
            curPage++;
        }
        System.out.println(count);
        //System.out.println(Arrays.toString(arr)+count);
    }
}

Problem solution in C++ programming.

#define _USE_MATH_DEFINES
#include <algorithm>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v, w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, K; cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	int x = 1, cnt = 0;
	for (int i = 0; i < N; i++) {
		int y = 0;
		for (int j = 1; j <= a[i]; j++) {
			if (j == x) cnt++;
			y++;
			if (y == K) {
				y = 0;
				x++;
			}
		}
		if (y) x++;
	}
	cout << cnt << endl;
}

Problem solution in C programming.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

struct prob{
    int problem_no;
    int page_no;
};

int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int n, k, page_number=1, counter=0;
    scanf("%d %d", &n, &k);
    int chapter[n];
    for(int i=1;i<=n;i++){
        scanf("%d", &chapter[i]);
        struct prob problem[chapter[i]];
        for(int j=1;j<=chapter[i];j++){
            problem[j].problem_no=j;
            problem[j].page_no=page_number;
            if((j%k==0) && (j!=chapter[i]))
                page_number++;
        }
        page_number++;
        for(int j=1;j<=chapter[i];j++){
            if(problem[j].problem_no==problem[j].page_no)
                counter++;
        }
    }
    printf("%d", counter);
    return 0;
}

Problem solution in JavaScript programming.

function processData(input) {
    
    var top = input.split('n')[0];
    var bot = input.split('n')[1];
    
    var chapcount = top.split(' ')[0];
    var maxq = top.split(' ')[1];
    var chaps = bot.split(' ');
    var pageoffset = 1;
    var speccount = 0;
    var specmem = [];
    for(var a = 0; a < chaps.length; a++){
        var chapqs = chaps[a];
        var pagecount = Math.ceil(chapqs/maxq);
        var qs = [];
        for(var q = 1; q <= chapqs; q++){qs.unshift(q); }
        //for(var q = 1; q <= chapqs; q++){qs.push(q); }
        
        for(var p = pageoffset; p < pagecount + pageoffset; p++){
           specmem.push([]);
           //specmem[p-1].push(qs.slice());
            
            
           if(qs.length >=maxq){
               for(var s = 1; s <= maxq; s++){
                    specmem[p-1].push(qs.pop());
               }
           }
           else{
               //console.log(p+"LENGTH"+qs.length);
               var qslength = qs.length;
                for(var s = 0; s < qslength; s++){
                    //console.log(s+":"+p+":"+qs.pop())
                    specmem[p-1].push(qs.pop());
               }
            }
        }
     
        pageoffset = pageoffset+ pagecount;
    }
    
    for(var a = 0; a < specmem.length; a++){
        var mem = specmem[a];
        //console.log((a+1)+":"+mem);
        for(var b = 0; b < mem.length; b++){
            
            if(a+1 == mem[b])speccount++;
        }
    }
    console.log(speccount);
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

Algorithms coding problems solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes