C++ Code to Check if All Bulbs Can Be Turned On

Arnab Chakraborty
Updated on 15-Mar-2022 06:46:48

392 Views

Suppose we have a number m and a nested list A with n sub-lists. Consider there are m bulbs, initially all are turned off. There are n buttons and each of them is connected to some set of bulbs. So A[i] is the set of bulbs that can be turned on by pressing ith switch. We have to check whether we can lit up all the bulbs or not.So, if the input is like A = [[1, 4], [1, 3, 1], [2]]; m = 4, then the output will be True, because by pressing all switches we can turn on ... Read More

C++ Code to Count Orders Collected When Client Calls

Arnab Chakraborty
Updated on 15-Mar-2022 06:44:25

330 Views

Suppose we have three numbers n, m and z. An office receives calls in every n minutes, and some deliveries come to office in every m minutes. Office is open for z minutes. We have to count the minimum number of orders are collected so there are no pending orders when client calls. Consider taking orders and talking with clients take exactly 1 minutes.So, if the input is like n = 1; m = 2; z = 5, then the output will be 2, because we need to collect orders which comes in second and fourth minutes.StepsTo solve this, we ... Read More

Count Number of Lucky Numbers with K Digits in C++

Arnab Chakraborty
Updated on 15-Mar-2022 06:42:47

1K+ Views

Suppose we have an array A with n elements, and also another number x. We know the lucky numbers are are positive numbers whose decimal representation only contains lucky digits 4 and 7. Form the given n positive integers. We have to count how many of those have not more than k lucky digits?So, if the input is like A = [44, 74, 474, 154]; k = 2, then the output will be 3, because there are three lucky numbers 44, 74 and 474 but 474 has three lucky digits which is more than k. Also 154 has one lucky ... Read More

Find Xth Element After Removing Numbers in C++

Arnab Chakraborty
Updated on 15-Mar-2022 06:38:35

227 Views

Suppose we have two numbers n and x. First n natural numbers are written on a blackboard. In ith (i starts from 1) operation, we remove ith number from the blackboard. When there are less than i numbers, we stop removal task. We have to find x-th remaining number after stopping removal.So, if the input is like n = 69; x = 6, then the output will be 12. In first operation, i = 1, so remove 1, then in second operation i = 2, but the sequence is 2, 3, 4 ... so second number is 3, remove 3, ... Read More

Find Maximum Stones We Can Pick from Three Heaps in C++

Arnab Chakraborty
Updated on 15-Mar-2022 06:36:24

272 Views

Suppose we have three numbers a, b and c. There are three heaps of stones with a, b, and c number of stones respectively. Each time we can do these operations −Take one stone from the first heap and two stones from the second heap (when the heaps have necessary number of stones)Take one stone from the second heap and two stones from the third heap (when the heaps have necessary number of stones)We have to count maximum how many stones we can collect?So, if the input is like a = 3; b = 4; c = 5, then the ... Read More

C++ Code to Disprove Given Prime Hypothesis

Arnab Chakraborty
Updated on 15-Mar-2022 06:34:12

203 Views

Suppose we have a number n. Let there is a hypothesis "There exists a positive integer n that for each positive integer m number (n·m + 1) is a prime number". We have to find such m as a counter example to disprove this statement.So, if the input is like n = 12, then the output will be 10, because 12*10 + 1 = 121 which is not prime.StepsTo solve this, we will follow these steps −if n < 3, then:    return n + 2 Otherwise    return n - 2ExampleLet us see the following implementation to get better ... Read More

C++ Code to Get Two Numbers in Range X with Given Rules

Arnab Chakraborty
Updated on 15-Mar-2022 06:32:01

281 Views

Suppose we have a number x. We have to find two integers a and b, such that both of them will be in between 1 and x, a is divisible by b, a * b > x but a/b < x. If not possible, return -1. So, if the input is like x = 10, then the output will be 6 and 3, (other answers are also possible)To solve this, we will follow these steps −if x < 2, then:    print -1    return print x and xExampleLet us see the following implementation to get better understanding −#include using namespace std; void solve(int x){    if (x < 2){       cout

Check Review Vote Status and Uncertainty in C++

Arnab Chakraborty
Updated on 15-Mar-2022 06:29:49

529 Views

Suppose we have three numbers x, y and z. On a review site there were x persons who would upvote, y persons who would downvote, and another group of z persons who would vote, but we do not know whether they would upvote or downvote. Each person can vote at most once. If there are more people upvote than downvote, the result will be "+"; if downvote count is greater, the result will be "-"; otherwise the result will be "0". Because of the z unknown persons, the result may be uncertain (i.e. there are more than one possible results). ... Read More

Count Years to Reach Certain Rank in an Army Using C++

Arnab Chakraborty
Updated on 15-Mar-2022 06:27:22

271 Views

Suppose we have an array D with n-1 elements and two values a and b. In an army, there are n ranks numbered from 1 to n. One needs D[i] years to rise from rank i to rank i+1. Amal has just reached new rank 'a' but he wants to reach rank 'b'. We have to count the number of years he will need to reach his goal.So, if the input is like D = [5, 6]; a = 1; b = 3, then the output will be 11.To solve this, we will follow these steps −n := size of ... Read More

C++ Code to Count Number of Unread Chapters

Arnab Chakraborty
Updated on 15-Mar-2022 06:24:55

211 Views

Suppose we have an array of pairs P. Where P[i] is in the form (l, r), and have another number k. Consider we are going to read a book with n chapters. so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. We have read some pages and marked the page with number k as the first page which was not read. We have to find the number of chapters we have not completely read yet. P[i] represents the chapter page numbers range.So, if the input is like P = ... Read More

Advertisements