Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 74 of 81

Maximize the sum of array by multiplying prefix of array with -1 in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Oct-2021 358 Views

We are given an integer array and the task is to firstly fetch the prefix of an array and then multiply it with -1, secondly calculate the prefix sum of an array and lastly find the maximum sum from the prefix array generated.Prefix array is generated as −First element of prefixArray[0] = first element of an arraySecond element of prefixArray[1] = prefixArray[0] + arr[1]Third element of prefixArray[2] = prefixArray[1] + arr[2]Fourth element of prefixArray[3] = prefixArray[2] + arr[3] …..etc.Let us see various input output scenarios for this -In − int arr[] = {2, 4, 1, 5, 2}Out − Prefix array is: ...

Read More

Minimum sum submatrix in a given 2D array in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Oct-2021 672 Views

We are given a 2-D array of integer elements forming the matrix. The task is to calculate the count of minimum sum by pulling the submatrix from the matrix so formed.Let us see various input output scenarios for this -In −int matrix[size][size] = { {2, 3, -1, 5}, {-2, 9, -1, 6}, { 5, 6, 9, -9}, { -6, 1, 1, 1} }Out −Minimum sum submatrix in a given 2D array is: -9Explanation −we are given a 2-D array of size 4x4 i.e. 4 rows and 4 columns. Now, we will find out the sub-matrix from the given matrix such ...

Read More

Minimum no. of iterations to pass information to all nodes in the tree in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 21-Oct-2021 880 Views

We are given a tree data structure with ‘n’ number of nodes. The given tree will have a root node and respective children which can be any number and further child can have any number of children. The task is to find the minimum number of iterations required by a root node of a tree to pass the information to all nodes in a tree. At a time, a node can pass information to one of its children and further one of its children can pass information to one of its children and meanwhile root node can pass information to ...

Read More

Minimum 1s to lend power to make whole array powerful using C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 21-Oct-2021 142 Views

We are given a binary array which can store digits 1’s and 0’s of any given size and an integer variable let’s say, base. The task is to calculate the minimum 1’s that can lend power to other elements of a binary array such that the entire array becomes powerful. An element can lend power to its adjacent element or any other elements within the distance less than base.Let us see various input output scenarios for this -In − int arr[] = {1, 1, 0, 1, 1, 0, 1}, int base = 7Out −Minimum 1s to lend power to make ...

Read More

Count of number of given string in 2D character array in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 29-Jan-2021 675 Views

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 More

Count Occurrences of Anagrams in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 29-Jan-2021 518 Views

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 More

Count Strictly Increasing Subarrays in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 29-Jan-2021 514 Views

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 More

Count numbers (smaller than or equal to N) with given digit sum in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 29-Jan-2021 2K+ Views

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 More

Construct Pushdown automata for L = {0(n+m)1m2n | m, n = 0} in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 07-Jan-2021 605 Views

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 More

Count of operations to make a binary string "ab" free in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 02-Dec-2020 374 Views

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 More
Showing 731–740 of 809 articles
« Prev 1 72 73 74 75 76 81 Next »
Advertisements