Programming Articles

Page 2259 of 2547

Maximum Erasure Value in C++

Kiran P
Kiran P
Updated on 04-Feb-2021 332 Views

Given an array of positive integers, the task is to erase a subarray containing all the unique elements. What you get by erasing the subarray is equal to the sum of its elements.Return the maximum sum of the current subarray by erasing the terms before or after it, we can get the maximum sum by erasing exactly one subarray.An array arr is called to be a subarray of a if it forms a contiguous subsequence of a that is if it is equal to a[l], a[l+1], ..., a[r] for some (l, r). For example, Input-1 −arr[ ] = { 1, 2, ...

Read More

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 29-Jan-2021 687 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 536 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 531 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

Divisibility by 64 with removal of bits allowed in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 28-Jan-2021 282 Views

In this tutorial, we are going to write a program that checks whether the given binary number is divisible by 64 or not.We have given a binary number and we can remove the bits to make it divisible by 64. After removing the bits, if the number is divisible by 64, then print Yes else No.The method that we are going to use is very simple. Let's see the steps to solve the problem.Initialize the binary number in string format.Iterate over the given binary number.Count the number of zeros.If the binary number contains more than or equal to 6 and ...

Read More

Distributing all balls without repetition in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 309 Views

In this tutorial, we are going to learn how to distribute n balls for k students without hurting anyone.The idea is simple, we have n balls in different colors that need to be distributed to the students. We don't have to give more than one ball of the same color to any student. If it is possible for a student to get more than one ball of the same color, then distribution should not happen.Let's see an example.Inputn = 10 k = 5 ballsColors = "rrrgbrbgbr"OutputYesNo color is more than the number of students (k). So, no student will get ...

Read More

Density of Binary Tree in One Traversal in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 325 Views

In this tutorial, we are going to learn how to find the density of the binary tree in a single traversal.The density of the binary tree is obtained by dividing the size of the tree by the height of the tree.The size of the binary tree is the total number of nodes present in the given binary tree.The height of the binary tree is the max depth of the leaf node from the root node.Let's see the steps to solve the problem.Initialize the binary tree dummy data.Find the size and height of the tree.Recursively count the height of the tree.Return ...

Read More

Principles of Risk Management and Paradigm in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2021 821 Views

Risk Management is the approach that is used to manage all available resources and make the best use of the resources available in the system.The project manager will analyse risks from all categories and there might be some risks in the working of the project in the runtime environment.Principles of Risk ManagementThere are 5 basic principles of Risk management. They are:GLOBAL PERSPECTIVE: This risk analysis of software in context of system and business problems planned to be solved. This analysis takes underconsideration the larger system definition, design and implementation.FORWARD LOOKING VIEW: This analysis considers all possible solutions to future risks to the product. Here, ...

Read More

File opening modes(r versus r+) in C++

sudhir sharma
sudhir sharma
Updated on 22-Jan-2021 3K+ Views

File handling in programming languages is very important for the interaction of programming with the memory for accessing files and fetching data in it.Using a program, you can read data from a file as well as write data to the file and do a lot more functions.Here, we will see reading of data from a file.In programming, before performing any operation you need to open the file. And there are multiple modes to open a file in the programming language. The access to the file is based on the mode it is opened with.Here we will learn about the difference between ...

Read More
Showing 22581–22590 of 25,466 articles
Advertisements