sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 46 of 98

Working with Array and Vectors using STL in C++

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

Array and vectors are very important data structures in competitive programming for solving problems. And the STL (Standard Template Library) in c++ programming provide some functions to perform operations of arrays and vectors.Let’s see some of these functions in action, Finding sum, Min and Max of the array/vector − In STL there are function that helps you to find the sum, max, and min of the array/vector. Functions with there function, Finding sumaccumulate(startIndex, endIndex, initialSum)Greatest element of the array/vecto*max_element(startIndex, endIndex)Smallest element of array/vector*min_element(startIndex, endIndex)Program to perform operations on array −Example#include using namespace std; int main(){    int array[] = ...

Read More

Word Ladder (Length of shortest chain to reach a target word) in C++

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

In this problem, we are given a dictionary and two words ‘start’ and ‘target’. Our task is to generate a chain (ladder) from start work to target word, the chain is created such that each word differs the other character by only one word and the word should also exist in the dictionary. The target word exists in the dictionary and also the length of all words is the same. The program will return the length of the shortest path from start to target.Let’s take an example to understand the problem, InputDictionary = {‘HEAL’, ‘HATE’, ‘HEAT’, ‘TEAT’, ‘THAT’, ‘WHAT’ , ...

Read More

Word formation using concatenation of two dictionary words in C++

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

In this problem, we are given a dictionary and a word. Our task is to check if the given wors can be formed using the concatenation of two dictionary words.While forming given words repetition of words is not legal.Let’s take an example to understand the problem, Inputdictionary = {“hello”, “tutorials”, “program” , “problem”, “coding”, “point”} word = “tutorialspoint”OutputyesExplanationtutorialspoint is created using tutorials and point.To solve this problem, we will store all elements of the dictionary in a prefix tree commonly known as a trie. And then search for the prefix of the word in the trie, if found split it ...

Read More

Woodall Number in C++

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

In this problem, we are given a number and our task is to check if the number is Woodall number or not.Woodall number is a special type of number which is of the form, Wn = n.2n -1First 5 Woodall numbers are 1, 7, 23, 63, 159Let’s take an example to understand the problem, InputX = 159OutputYesTo solve this problem, we will observe the number, if the number is even then it cannot be Woodall and then check for the number. To check, add the number by 1 and recursively divide the number by 2. after each division count the ...

Read More

Aho-Corasick Algorithm for Pattern Searching in C++

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

In this problem, we are given an input string and an array arr[]. Our task is to find all occurrences of all words of the array in the string. For this, we will be using the Aho-Corasick Algorithm for Pattern Searching.String and pattern searching is an important thing in programming. And in programming, the better the algorithm the more practical uses it can have. Aho-Corasick algorithm is a very important and powerful algorithm that makes string searching easy. It is kind of a dictionary matching algorithm, matching all the strings simultaneously. The algorithm uses the Trie data structure for its ...

Read More

Ways to write N as sum of two or more positive integers in C++

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

In this problem, we are given an integer n. Our task is to find the total number of ways in can be expressed as sum of two or more positive integers.Let’s take an example to understand the problem, InputN = 4Output5Explanation4 can be written as the sum in these ways, 4, 3+1, 2+2, 2+1+1, 1+1+1+1To solve this problem, we will use Euler’s recurrence formula. For a number n the total number of ways it can be generated p(n) by, Σ∞n=0 p(n)xn = Π∞k=1 (1/(1-xk ))Using this formula, we will derive formula for p(n), p(n) = p(n-1) + p(n-2) - p(n-5) ...

Read More

Ways to sum to N using array elements with repetition allowed in C++

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

In this problem, we are given an array of integers and a number N. Our task is to count the total number of ways N can be generated by adding elements of the array. All combinations and repetitions are allowed.Let’s take an example to understand the problem, Inputarr = {1, 3, 5} N = 6Output8ExplanationThe ways are −5+1, 1+5, 3+3, 3+1+1+1, 1+3+1+1, 1+1+3+1, 1+1+1+3, 1+1+1+1+1+1To solve this problem, we need to use a different approach as all types of combinations will be treated differently so, if the number is a sum of 4 elements of array 4 different ways are ...

Read More

Ways to select one or more pairs from two different sets in C++

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

In this problem, we are given two positive numbers n and m (n > 1;       x = (1LL * x * x) % p;    }    return res; } void calculate(int n){    fact[0] = inverseMod[0] = 1;    for (int i = 1; i

Read More

Ways to remove one element from a binary string so that XOR becomes zero in C++

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

In this problem, we are given a binary string. Our task is to count the total number of ways in which we can remove one element such that XOR becomes zero.Let’s take an example to understand the problem, Inputn = 11010Output3to solve this problem, we need the logic that if the number of 1’s is even then XOR of the string will be 0, otherwise, we need to remove one 1 from the string. We can remove any number of 0’s without affecting the XOR.Program to show the implementation of our solution, Example#include #include using namespace std; int wayXorZero(string binaryString){ ...

Read More

Bessel's Interpolation in C++

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

Interpolation is a type of estimation technique of unknown value which lies between know values. Interpolation is the process of constructing new data points between the range of a discrete set of know data points.An application or reason to use interpolation is that it might reduce computation costs. When the formula (function) to calculate certain values is too complicated or costly to compute, we prefer using interpolation. A few data points are calculated using the original function, the rest of them can be estimated using interpolation. These may not be completely accurate but fairly close!So basically here the reduced computation ...

Read More
Showing 451–460 of 975 articles
« Prev 1 44 45 46 47 48 98 Next »
Advertisements