Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 75 of 81

Count rotations of N which are Odd and Even in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 01-Dec-2020 225 Views

We are given a number N. The goal is to count the rotations of N that make an odd number and rotations that make an even number. If the number N is 123 its rotations would be 123, 321, 132. The odd rotations are 123 and 321 ( 2 ) and even rotation is 132 ( 1 ).Let us understand with examples.Input − N= 54762Output −Count of rotations of N which are Odd are − 2Count of rotations of N which are Even are − 3Explanation − Rotations are −54762, 25476, 62547, 76254, 47625.Even rotations are 3 − 54762, 25476, ...

Read More

Count of distinct sums that can be obtained by adding prime numbers from given arrays in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 31-Oct-2020 255 Views

We are given two arrays containing prime and non prime numbers. The goal is to find the count of distinct sums of pairs of prime numbers in each array. We will do this by making a pair of two primes from each array, take their sum and add them to set sums. In the end the size of the set is the number of distinct sums of primes. Let's understand with examples. Input Arr1[] = { 1, 2, 3 } Arr2[] = { 2, 3, 4} Output Distinct Sums of primes :3 Explanation Prime pairs ...

Read More

Count numbers whose difference with N is equal to XOR with N in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 31-Oct-2020 177 Views

We are a number N. The goal is to find numbers between 0 and N whose difference with N is equal to XOR with N.We will do this by traversing no. from i=0 to i

Read More

Count pieces of the circle after N cuts in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 31-Oct-2020 169 Views

We are given an integer N which represents the number of cuts applied on a 2D-circle. Each circle divides the circle in two halves. Goal is to find the pieces of the circle after N cuts.Number of pieces= 2 * no. of cutsLet’s understand with examples.Input − N=1Output − Pieces of circle: 2Explanation −Input − N=3Output − Pieces of circle: 6Explanation −Approach used in the below program is as followsWe take N for a number of cuts.Take pieces=1*N.Print the result..Example#include using namespace std; int main(){    int N=2;    Int pieces=2*N;    cout

Read More

Maximum number of Zombie processes a system can handle in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 17-Aug-2020 260 Views

Given the task is to find the maximum number of Zombie processes that a system can handle or in other words, the program does not stop its execution.A Zombie process (also known as defunct process) is a process that has completed its process via exit() (system call) but still has an entry in the process table.Approach used in the below program as followsNote that should be added in order to run the program.In main() function initialize num = 0 of type int which we will iterate until the program stops being executed.To initiate a zombie process create a while statement ...

Read More

Upper bound and Lower bound for non increasing vector in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 14-Aug-2020 4K+ Views

In this article we are going to discuss the vector::upper_bound() and vector::lower_bound() for an array sorted in non-increasing order in C++ STL.Vectors are similar to the dynamic arrays; they have the ability to modify its size itself whenever a value is inserted into or removed from the container where we are storing the value.In a Vector, lower bound returns an iterator pointing to the first element in the range that does not compare the given value. Upper Bound returns an iterator pointing element in the range that smaller than given value.Input 30 30 30 20 20 20 10 10Output Lower bound of ...

Read More

Split the sentence into words in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 14-Aug-2020 2K+ Views

Given is the task to split the sentence into words. In this, we will separate all the words present in sentence.Input I am a good boyOutput I am a good boyIn the above example we will print the single word in single line.Example#include #include #include Using namespace std; void split( string st){    String word = “ “;    for ( char s : st){       If (s== ‘ ‘){          Cout

Read More

Maximum and Minimum element of a linked list which is divisible by a given number k in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 14-Aug-2020 253 Views

A linked list is a linear data structure in which elements are linked via pointers. Each element or node of a linked list has a data part and link, or we can say pointer to the next element in sequence. The elements can take noncontiguous locations in memory.We are given a singly linked list in which there is a data part and link to the next element. The other input is a number K. Task is to find the Maximum and Minimum element of a linked list which is divisible by the number K. The linear linked list can only ...

Read More

Maximum adjacent difference in an array in its sorted form in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 14-Aug-2020 1K+ Views

We are given with an array. The array need not be sorted. The task is to find the maximum difference between adjacent elements of that array in its sorted form. So the first thing is to sort the array in increasing or decreasing order. Then we will iterate the array and calculate the adjacent difference of Arr[i+1]-Arr[i]. Then for each iteration we will compare this difference with the one which is found maximum so far.Input − Arr[] = [ 1, 5, 10, 2, 7 ]Output − Maximum adjacent difference in array in its sorted form is 3.Explanation − Sorted Arr[] ...

Read More

Maximize the sum of X+Y elements by picking X and Y elements from 1st and 2nd array in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 14-Aug-2020 312 Views

For the given two arrays each of size N, the task is to find the maximum sum by choosing X elements from array 1 and Y elements from array 2.Let’s now understand what we have to do using an example −Input arr1 = {1, 2, 3, 4, 5} ; X=2 arr2 = {1, 3, 5, 2, 7}; Y=3Output Maximum sum here is : 24Explanation − We are selecting 2 number(s) from arr1 and 3 from arr2. Largest 2 of arr1 are 4, 5 and largest 3 of arr2 are 3, 5, 7. Total sum of these 5 elements is 24 which is ...

Read More
Showing 741–750 of 809 articles
« Prev 1 73 74 75 76 77 81 Next »
Advertisements