Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

Dice Roll Simulation in C++

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

Suppose a die simulator generates a random number from 1 to 6 for each roll. We want to introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times. Consider we have an array of integers rollMax and an integer n, we have to return the number of distinct sequences that can be obtained with exact n rolls. The two sequences are considered different if at least one element differs from each other. So if n is 2, then rollMax = [1, 1, 2, 2, 2, 3], then the output will ...

Read More

Templates and Static variables in C++

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

In this tutorial, we will be discussing a program to understand templates and static variables in C++.In case of function and class templates, each instance of the templates has its own local copy of the variables.Example#include using namespace std; template void fun(const T& x){    static int i = 10;    cout

Read More

is_standard_layout template in C++

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

In this article we will be discussing the working, syntax and examples of std::is_standard_layout template in C++ STL.is_standard_layout is a template which comes under the header file. This template is used to check whether the given type T is a standard layout or not.What is a standard layout in C++?Standard Layout type is a type in which is of simple linear structure (like we see in array) and access control which can be easily used to communicate with the program written in other programming languages. This is a type which is written with the idea of one code for ...

Read More

Maximum of all Subarrays of size k using set in C++ STL

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

In this tutorial, we will be discussing a program to get maximum of all subarrays of size k using set in C++ STL.For this we will be provided with a array of size N and integer K. Our task is to get the maximum element in each K elements, add them up and print it out.Example#include using namespace std; //returning sum of maximum elements int maxOfSubarrays(int arr[], int n, int k){    set q;    set::reverse_iterator it;    //inserting elements    for (int i = 0; i < k; i++) {       q.insert(pair(arr[i], i));    }   ...

Read More

Bitwise ORs of Subarrays in C++

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

Suppose we have an array A of non-negative integers. For every (contiguous) subarray say B = [A[i], A[i+1], ..., A[j]] (with i

Read More

Meeting Scheduler in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have the availability time slots lists slots1 and slots2 of two people and a meeting duration d, we have to find the earliest time slot that works for both of them and is of duration d. If there is no common time slot that satisfies the requirements, then show an empty array. Here the format of a time slot is an array of two elements [start, end] representing an inclusive time range from start to end. we can assume that no two availability slots of the same person intersect with each other. That is, for any two time ...

Read More

match_results begin() and end() function in C++ STL

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

In this article we will be discussing the working, syntax and examples of match_results::begin() and match_results::end() functions in C++ STL.What is a match_results in C++ STL?std::match_results is a specialized container-like class which is used to hold the collection of character sequences which are matched. In this container class a regex match operation finds the matches of the target sequence.What is match_results::begin()?match_results::begin() function is an inbuilt function in C++ STL, which is defined in header file. This function returns an iterator which is pointing to the first element in the match_results object. The match_results::begin() and match_results::end() are together used to ...

Read More

RLE Iterator in C++

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

Suppose we have to create an iterator that iterates through a run-length encoded sequence. Here the iterator is initialized by calling RLEIterator(int[] A), where A is a run-length encoding of a sequence. So we can say that for all even i, A[i] tells us the number of times that the non-negative integer value A[i+1] is repeated in the sequence. Here iterator supports one function −next(int n): This function exhausts the next n elements (n >= 1) and returns the last element exhausted in this way. So if there is no element left to exhaust, next returns -1 instead.Suppose we start ...

Read More

Polybius Square Cipher in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given a string and we have to find its integer encryption using the Polybius Square Cipher.Polybius Square CipherIt is a table that is used for the conversion of letters into numbers. The table for English encryption is a 5X5 table i.e. contains 25 cells for 26 alphabets of an English dictionary. The letters i and j are kept together in a single cell.The following table shows a Polybius square Cipher −123451ABCDE2FGHI, JK3LMNOP4QRSTU5VWXYZThe letter of the tables can be randomized. Also, the size of the table can be changed based on the number of alphabets of ...

Read More

Toss Strange Coins in C++

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

Suppose we have some coins. The i-th coin has a probability prob[i] of facing heads when tossed. We have to show the probability that the number of coins facing heads equals target if you toss every coin exactly once. So if the prob array is like [0.5, 0.5, 0.5, 0.5, 0.5] and target is 0, then the output will be 0.03125.To solve this, we will follow these steps −n := size of prob arraycreate one 2d array of size n x (target + 5)set dp[0, 0] = 1 – prob[0] and dp[0, 1] := prob[0]for i in range 1 to ...

Read More
Showing 27721–27730 of 61,297 articles
Advertisements