Programming Articles

Page 1366 of 2547

Decode String in C++

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

Suppose we have an encoded string; we have to return its decoded string. The rule for encoding is: k[encoded_string], this indicates where the encoded_string inside the square brackets is being repeated exactly k times. We can assume that the original data does not contain any numeric characters and that digits are only for those repeat numbers, k. So if the input is like “1[ba]2[na]”, then the output will be “banana”.To solve this, we will follow these steps −create one empty stack, set i := 0while i < size of a stringif s[i] is ‘]’res := delete element from the stack ...

Read More

ilogb() function in C++ STL

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

In this article, we will be discussing the working, syntax, and examples of ilogb() function in C++.What is ilogb()?ilogb() function is an inbuilt function in C++ STL, which is defined in iostream> using namespace std; int main(){    int output, var = 2;    output = ilogb(var);    cout

Read More

Longest Substring with At Least K Repeating Characters in C++

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

Suppose we have a string s, and we have to find the length of the longest substring T of that given string (consists of lowercase letters only) such that every character in T appears no less than k times. So if the string is “ababbc” and k = 2, then the output will be 3 and longest substring will be “ababb”, as there are two a’s and three b’s.To solve this, we will follow these steps −create one recursive function called longestSubstring(), this takes string s and size kif k = 1, then return the size of the stringif size ...

Read More

logical_and in C++

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

In this article, we will be discussing the working, syntax, and examples of logical_and function object class in C++.What is logical_and?logical_and binary function is an inbuilt binary function object class in C++, which is defined in a header file. logical_and is a binary function used to give the result of logical “and” operation between two arguments.Logical AND is the binary operation that returns true only and only if both the binary values are true.Syntax of logical_andTemplate struct logical_and : binary_function {    T operator() (const T& a, const T& b) const {return a&b&; } };Template parametersThe function accepts the ...

Read More

Queue Reconstruction by Height in C++

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

Consider we have a random list of people standing in a queue. If each person is described by a pair of integers (h, k), where h is the height and k is the number of people in front of him, who have a height greater than or equal to h. We have to define one method to reconstruct the queue. So if the given array is like [[7, 0], [4, 4], [7, 1], [5, 0], [6, 1], [5, 2]], then the output will be [[5, 0], [7, 0], [5, 2], [6, 1], [4, 4], [7, 1]]To solve this, we will ...

Read More

Modulus function in C++ STL

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 4K+ Views

In this article, we will be discussing the working, syntax, and examples of modulus functions in C++.What is modulus function C++?modulus function object class in C++, which is defined in header file. modulus function is a binary function object class used to get the result of the modulus operation of the two arguments. This function works the same as the operator ‘% ‘.Syntax of modulus functionTemplate struct modulus : binary_function {    T operator() (const T& a, const T& b) const {return a%b; } };Template parametersThe function accepts the following parameter(s) −T − This is the type of the ...

Read More

Partition Equal Subset Sum in C++

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

Suppose we have a non-empty array containing only positive numbers, we have to find if the array can be partitioned into two subsets such that the sum of elements in both subsets is the same. So if the input is like [1, 5, 11, 5], the output will be true. As this array can be partitioned as [1, 5, 5] and [11]To solve this, we will follow these steps −n := size of the arraysum := 0for i := 0 to n – 1sum := sum + nums[i]if sum is odd, return falsesum := sum / 2create one array called ...

Read More

Word Ladder in C++

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

Suppose we have two words (beginWord and endWord), and we have dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that −Only one letter can be converted at a time.In each transformed word must exist in the word list. The beginWord is not a transformed word.We have to keep in mind that −Return 0 when there is no such change sequence.All words have the same length.All words contain only lowercase characters.We can assume no duplicates in the word list.So if the input is like: beginWord = "hit", endWord = "cog", and wordlist = ["hot", ...

Read More

Raw string literal in C++ program

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

In this article, we will be discussing the raw string literal in C++, its meaning, and examples.There are escape characters in C++ like “” or “\t”. When we try to print the escape characters, it will not display on the output. To show the escape characters on the output screen we use a raw string literal by using R”(String with escape characters)”. After using R in the front of the string the escape character will be displayed on the output.ExampleLet’s understand this with the help of an example#include using namespace std; int main(){    string str = "tutorialspoint" ; ...

Read More

Reconstruct Original Digits from English in C++

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

Suppose we have a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order. There are some properties −Input is guaranteed to be valid and can be transformed to its original digits. That means invalid inputs such as "abc" or "zerone" are not permitted.Input length is less than 50, 000.So if the input is like “fviefuro”, then the output will be 45.To solve this, we will follow these steps −nums := an array that is holding the numbers in English letter from 0 to 9.make one array count of size 10ans := an empty ...

Read More
Showing 13651–13660 of 25,466 articles
Advertisements