Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Sunidhi Bansal
Page 65 of 81
Count of number of given string in 2D character array in C++
The following problem is an example of daily newspaper crossword, here we are given a 2-Dimensional character array and the problem statement is to find out the given word from the 2-Dimensional character array maze.The search algorithm includes finding the individual characters from Top-to-Bottom, Right-to-Left and vice-versa but not diagonally.Let us understand with examplesInput- String word-LAYS2D String[ ] - { "LOAPYS", "KAYSOT", "LAYSST", "MLVAYS", "LAYSAA", "LAOYLS" };Output- Count of number of given strings in 2D character array: 7Explanation - As we are given with the string array of words and from them, we have to find the word “LAYS” which can ...
Read MoreCount Occurrences of Anagrams in C++
We are given an input as a text stream and a word, and the task is to find out the count of occurrences of anagrams of the word in the given text stream. Anagrams are generated by rearranging letters from a word which ends up being a different word or phrase like anagrams of words in a statement "New York Times" can be formed as "Monkeys write".For ExampleInput: String string-: “workitwrokoffowkr” word = “work” Output: Count of occurrences of anagram in the string are: 3Explanation: The possible anagrams for the word “work” are work, wrok, rowk, owkr, etc. In the ...
Read MoreCount Strictly Increasing Subarrays in C++
We are given an array containing integer elements and the task is to firstly calculate the subarray out of the given array and then check whether the elements in a subarray are in increasing order or not. If yes, then we will consider the subarray else it will be discarded.The approach here is to stop further checking the subarray if the elements in 0th and 1th position are not in increasing order.For Example- in C++Input: int a[] = {1, 7, 5}Output: Count of strictly increasing subarrays is 1Explanation - The possible subarrays include {1, 7, 5}, {1, 7}, {7, 5} where ...
Read MoreCount numbers (smaller than or equal to N) with given digit sum in C++
Given a string str containing a number and a sum total as input. The goal is to find numbers upto str that have sum of digits equal to total.Let us understand with examples.For ExampleInput - N=”110” sum=5Output - Count of numbers smaller than or equal to N with given digit sum are: 7Explanation - The numbers upto 110 that have sum of digits equal to 5 are :-5, 14, 23, 32, 41, 50 and 104.Input - N=”1000” sum=3Output - Count of numbers smaller than or equal to N with given digit sum are: 10Explanation - The numbers upto 1000 that ...
Read MoreConstruct Pushdown automata for L = {0(n+m)1m2n | m, n = 0} in C++
We are given with a language “L” and the task is to construct a pushdown automata for the given language which explains that the occurrences of 0’s will be the addition of occurrences of 1’s and 2’s and also, occurrence of 1 and 2 will be minimum one which can also makes the string NULL and it should be accepted by the automata.What is pushdown Automata?A pushdown automata or pushdown automaton or PDA is a technique to implement a context−free grammar in a similar way we design Deterministic Finite Automaton or DFA for a regular grammar. A DFA can operate ...
Read MoreCount of operations to make a binary string “ab” free in C++
We are given a string which can contain “ab” and the task is to calculate the count of operations required to remove or delete “ab” from the string. So, our task is to firstly check whether the string contains “ab” or not if yes then we have to make string “ab” free.Input − string str = "ababaa"Output − Count of operations to make a binary string “ab” free are − 4Explanation − As we can see in the string “ab” pattern is occurring two times so we will replace “ab” with “bba” so the count of operations is 1 and ...
Read MoreCount rotations of N which are Odd and Even in C++
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 MoreCount of distinct sums that can be obtained by adding prime numbers from given arrays in C++
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 MoreCount numbers whose difference with N is equal to XOR with N in C++
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 MoreCount pieces of the circle after N cuts in C++
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