Bitmasking and Dynamic Programming in C++

sudhir sharma
Updated on 05-Aug-2020 07:41:03

3K+ Views

First, we will learn about bitmasking and dynamic programming then we will solve a problem related to it that will solve your queries related to the implementation.Bitmask also known as mask is a sequence of N -bits that encode the subset of our collection. The element of the mask can be either set or not set (i.e. 0 or 1). This denotes the availability of the chosen element in the bitmask. For example, an element i is available in the subset if the ith bit of mask is set. For the N element set, there can be a 2N mask ... Read More

C Programming Language Standard

sudhir sharma
Updated on 05-Aug-2020 07:35:32

1K+ Views

In this problem, we will learn about the standards that are defined in the C programming language. These are those standard ways in which the program is to be ideally compiled by the compiler as defined by the development community.To understand what I am saying take an easy example of a common C program that you all must have encountered and have seen the issue coming but haven’t got deep into it.The main() function’s void return type −See the following program −void main() {    //program code }This program will run ok if we use the turbo c compiler but ... Read More

Store Student Records as Structures and Sort by Name in C

sudhir sharma
Updated on 05-Aug-2020 07:34:38

2K+ Views

In this problem, we are given a student’s record which contains student_id, student_name, student_percentage. Our task is to create a C program to store student records as structure and sort them by name.Let’s take an example to understand the problem, Input − student record ={{ student_id = 1, student_name = nupur, student_percentage = 98}, { student_id = 2, student_name = Akash, student_percentage = 75}, { student_id = 3, student_name = Yash, student_percentage = 62}, { student_id = 4, student_name = Jyoti, student_percentage = 87}, { student_id = 5, student_name = Ramlal, student_percentage = 80}}Output − student record ={{ student_id = ... Read More

Content Spoofing

Sunidhi Bansal
Updated on 04-Aug-2020 13:37:59

565 Views

Content Spoofing is the term used to define the type of attack by malicious programmers in which they present a fake website as a legitimate one to the user by text injection or html injection. When a web application does not properly handle the data supplied by the user using search etc. then the attacker can take advantage of such a situation and inject additional parameters that go unnoticed by the user. This leads to landing on another web page that looks the same as the original webpage. That page can ask the user to input information which is confidential ... Read More

Maximum Elements That Can Be Crossed Using Given Units of A and B in C++

Sunidhi Bansal
Updated on 04-Aug-2020 13:02:27

113 Views

Given a binary array arr[] and two variables a and b with some initial values. To cross an element in the array arr[] there are two ways −If arr[i] == 1, then 1 unit can be used from a, with no change in b. If 1 unit is used from b, then a increases by 1 unit. (Note that the value of a cannot be incremented above its original value.)If arr[i] == 0, then 1 unit can be used from a or b.Let’s now understand what we have to do using an example −Inputarr[] = {0, 0, 0, 1, 1}, ... Read More

Maximum Elements That Can Be Made Equal with K Updates in C++

Sunidhi Bansal
Updated on 04-Aug-2020 12:53:47

375 Views

Given the task is to find the maximum number of elements that can be made equal in a given array after incrementing its elements by at-most k times.Let’s now understand what we have to do using an example −Inputa[] = {1, 3, 8}, k = 4Output2ExplanationHere we can obtain two fours by incrementing 1 three times and incrementing 3 four times, that makes a[] = {4, 4, 8}Inputarr = {2, 5, 9}, k = 2Output0Approach used in the below program as followsIn main() function initialize int a[], size and k to store the array elements, size of array and the ... Read More

Maximum Distinct Lowercase Alphabets Between Two Uppercase in C++

Sunidhi Bansal
Updated on 04-Aug-2020 12:50:31

293 Views

Given the task is to find the maximum number of distinct lower case alphabets that are present between two upper case alphabets in the given string.Let’s now understand what we have to do using an example −Inputstr = “JKyubDoorG”Output3Explanation“yub” is present between the two upper case alphabets K and D which makes the count 3.“oor” is also present between the two upper case alphabets D and G which makes the count 2 as ‘o’ is a repeating alphabet and we are looking for distinct alphabets.Therefore, the output is 3.Inputstr = “ABcefsTaRpaep”Output4Approach used in the below program as followsIn function Max() ... Read More

Maximum Difference of Zeros and Ones in Binary String in C++

Sunidhi Bansal
Updated on 04-Aug-2020 12:45:15

344 Views

Given the task is to find a sub-string from a given binary string and then the maximum difference between the number of zeroes and the ones.Let’s now understand what we have to do using an example −Inputstr = “100100110”Output2ExplanationIn the sub-array from the position 1 to 5 (“00100”), the difference between the zeros and ones = 4 – 1 = 3 which is the maximum that can be found.Inputstr = “00000”Output5Approach used in the below program as followsIn main() function create a string str to store the binary string. Also initialize a variable int size to store the size of ... Read More

Maximum Difference of Zeros and Ones in Binary String (O(N) Time) in C++

Sunidhi Bansal
Updated on 04-Aug-2020 12:41:03

247 Views

Given the task is to find a sub-string from a given binary string and then the maximum difference between the number of zeroes and the ones.Let’s now understand what we have to do using an example −Inputstr = “10010110”Output2ExplanationIn the sub-array from the position 1 to 4 (“0010”), the difference between the zeros and ones = 3 – 1 = 2 which is the maximum that can be found.Inputstr = “00000”Output5Approach used in the below program as followsIn main() function create a string str to store the binary string. Also declare an array int arr[str.length()+1];Set all elements of arr[] = ... Read More

Maximum Decimal Value Path in a Binary Matrix in C++

Sunidhi Bansal
Updated on 04-Aug-2020 12:37:54

153 Views

Given the task is to find the maximum integer value that can be obtained while travelling in a path from the top left element to the bottom right element of a given square binary array, that is, starting from index [0][0] to index [n - 1][n - 1].While covering the path we can only move to right ([i][j + 1]) or to the bottom ([i + 1][j])The integer value will be calculate using the bits of the traversed path.Let’s now understand what we have to do using an example −Inputm = {    {1, 1, 1, 1},    {0, 0, ... Read More

Advertisements