Programming Articles

Page 1381 of 2547

Time Needed to Inform All Employees in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 514 Views

Suppose we have a company has n employees with a unique ID for each employee. These IDs are ranging from 0 to n - 1. The head of the company has is the one with headID. Each employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, manager[headID] = -1. Also it's guaranteed that the subordination relationships have a tree-like structure. Here the head of the company wants to inform all the employees of the company of an urgent piece of news. He can inform his direct subordinates and they ...

Read More

negative_binomial_distribution in C++ with Examples

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 235 Views

In this tutorial, we will be discussing a program to understand negative_binomial_distribution in C++.This function follows the negative Binomial discrete distribution and produces integers according to this random distribution.Example#include using namespace std; int main() {    //setting number of experiments    const int exps = 10000;    const int numberstars = 100;    default_random_engine generator;    negative_binomial_distribution distribution(4, 0.5);    int p[10] = {};    for (int i = 0; i < exps; ++i) {       int counting = distribution(generator);       if (counting < 10)          ++p[counting];    }    cout

Read More

Position of rightmost common bit in two numbers in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 270 Views

In this problem, we are given two numbers M and N. Our task is to print the position (index) of the rightmost common bit of the two numbers.Let’s take an example to understand the problem, Input − N = 4 , M = 7Output − 3Explanation − (4)2 = 100 , (7)2 = 111. The rightmost common bit is at index 3.To solve this problem, we will have to find all the same bits of the numbers. To find all same bits we will find xor of M and N. Then we will find the rightmost bit in the negation ...

Read More

is_signed template in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 293 Views

In this article we will be discussing the working, syntax and examples of std::is_signed template in C++ STL.is_ signed is a template which comes under header file. This template is used to check whether the given type T is a signed type or not.What is a signed type?These are the basic arithmetic types, which contains sign value with them. All arithmetic data types are either signed and unsigned.Like we want to show the values in negative we use signed type.Like: -1 is signed int and -1.009 is signed float.By default all the types are signed to make them unsigned ...

Read More

Position of rightmost bit with first carry in sum of two binary in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 174 Views

In this problem, we are given two positive integers N and M. Our task is to print the rightmost bit that generates the first carry bit in the binary addition of the sum of N and M.Let’s take an example to understand the problem, Input − N = 5, M = 14Output − 3Explanation −(5)2 = 0101 , (14)2 = 1110 Sum 0101 +   1110     10011To solve this problem, we will consider some observations from boolean algebra.The sum will generate a carry when both numbers are 1. So, we will find all bits where carry is generated. ...

Read More

is_unsigned template in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 344 Views

In this article we will be discussing the working, syntax and examples of std::is_unsigned template in C++ STL.is_unsigned is a template which comes under header file. This template is used to check whether the given type T is an unsigned type or not.What are unsigned data types in C++?Unsigned data types are those which we use knowing the values will not go in negative, like roll number, id of random numbers, etc.To make a type as unsigned we use keyword unsigned as prefix of the data type like −unsigned int;unsigned float;Syntaxtemplate is_unsigned;ParametersThe template can have only parameter of type ...

Read More

Koko Eating Bananas in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 527 Views

Suppose we have N piles of bananas, the i-th pile has piles[i] bananas. Here the guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed is K. Each hour, she takes some pile of bananas, and eats K bananas from that pile. If the pile has less than K bananas, then she consumes all of them instead, and won't eat any more bananas during this hour. Consider Koko likes to eat slowly, but still wants to finish eating all the bananas before the guards come back. We have to find the minimum integer ...

Read More

Position of a person diametrically opposite on a circle in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 249 Views

In this problem, we are given two integers N and M. there is a circle and N people are standing on it. M denotes the position of a person. Our task is to print the position of the person opposite to M.Let’s take an example to understand the problem, Input − N = 6, M = 3Output − 6Explanation −To solve this problem, there will be two cases, one if the position is greater than half the position (second half), the opposition will be the first half and vise versa.Let’s create a formula for this mathematically, Case 1 − if ...

Read More

How to store Data Triplet in a Vector in C++?

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 727 Views

In this tutorial, we will be discussing a program to understand how to store a Data triplet in a vector in C++.To store three elements in a single cell of a vector we will creating a user defined structure and then make a vector from that user defined structure.Example#include using namespace std; struct Test{    int x, y, z; }; int main(){    //creating a vector of user defined structure    vector myvec;    //inserting values    myvec.push_back({2, 31, 102});    myvec.push_back({5, 23, 114});    myvec.push_back({9, 10, 158});    int s = myvec.size();    for (int i=0;i

Read More

is_void template in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 360 Views

In this article we will be discussing the working, syntax and examples of std::is_void template in C++ STL.is_void is a template which comes under the header file. This template is used to check whether the given type T is a void type or not.What is a void type in C++?In simple words void means “empty” or “nothing”. When we declare a function as void then it is assumed that this function will return nothing.We also declare void pointers, which are supposed to left unspecified. However, they must be referenced to another variable of other type, before the pointer is ...

Read More
Showing 13801–13810 of 25,466 articles
Advertisements