Maximum Number of Segments That Can Contain Given Points in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:46:29

285 Views

Given the task is to find the maximum of segments that can contain the given points.Given an array a1[] with size n1 and two integers A and B are given. From the given array a1[], n1 line segments can be formed with starting and ending points as a1[i] – A and a1[i] + B respectively.Another array a2[] is given with n2 number of points. These points have to be assigned to the line segments such that the number of line segments than have been assigned a point is maximum. Note that a single point can be assigned only once to ... Read More

Maximum Number of Removals of Given Subsequence from a String in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:43:55

230 Views

Given the task is to find the maximum number of removals of given subsequence from a string. A string s is given and we have to find the maximum number of subsequence ‘abc’ that can be removed from the string.Let’s now understand what we have to do using an example:Inputs = ‘dnabcxy’Output1Explanation − Only one subsequence of ‘abc’ can be found in the given string (‘dnabcxy’), therefore the output is 1.Inputs = ‘zcabcxabc’Output2 (‘zcabcxabc’)Approach used in the below program as followsIn Max() function initialize variables i, a, ab, abc with value = 0 and of type int.Loop from i=0 till ... Read More

Maximum Number of People That Can Be Killed with Strength P in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:41:53

213 Views

Given the task is to find the maximum number of people that can be killed with strength P. Consider a row with infinite people and each of them have an index number starting from 1.The strength of the sth person is represented by s2. After killing a person with s strength your strength also decreases by s.Let’s now understand what we have to do using an example −InputP = 20Output3ExplanationStrength of 1st person = 1 * 1 = 1 < 20, therefore 1st person can be killed. Remaining strength = P – 1 = 20 – 1 = 19 Strength ... Read More

Maximum Length Subsequence with Difference Between Adjacent Elements as 0 or 1 - Set 2 in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:40:47

202 Views

We are given an array of any size and the task is to find the subsequence in the given array with the elements having difference between adjacent elements as 0 or 1.Input − int arr[] = { 2, 1, 5, 6, 3, 4, 7, 6}Output − Maximum length subsequence with difference between adjacent elements as either 0 or 1 is: 3Explanation − The subsequence of adjacent elements in an array with difference as 0 or 1 are {2, 1}. Therefore, the maximum length of subsequence is 2.Input − int arr[] = { 2, 1, 7, 6, 5}Output − Maximum length ... Read More

Maximum Length Subsequence with Difference Between Adjacent Elements as Either 0 or 1 in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:38:53

845 Views

We are given an array of any size and the task is to find the subsequence in the given array with the elements having difference between adjacent elements as 0 or 1.Input − int arr[] = { 2, 1, 5, 6, 3, 4, 7, 6}Output − Maximum length subsequence with difference between adjacent elements as either 0 or 1 is − 3Explanation − The subsequence of adjacent elements in an array with difference as 0 or 1 are {2, 1}. Therefore, the maximum length of subsequence is 2.Input − int arr[] = { 2, 1, 7, 6, 5}Output − Maximum ... Read More

Maximum Length Subarray with Difference 0 or 1 in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:38:08

684 Views

We are given an array of any size and the task is to find the subarray of the given array with the elements having difference between adjacent elements as 0 or 1.Input − int arr[] = { 2, 1, 5, 6, 3, 4, 7, 6}Output − Maximum length subarray with difference between adjacent elements as either 0 or 1 are − 2Explanation − The adjacent elements in an array with difference as 0 or 1 are {2, 1}, {5, 6}, { 3, 4} and {7.6}. Therefore, the maximum length of subarray is 2.Input − int arr[] = { 2, 1, ... Read More

Maximum Contiguous Array Elements with Same Set Bits in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:35:36

158 Views

We are given with an unsorted array of integer elements and the task is to calculate the two major things i.e.Elements with same number of set bitsAlso, Elements with the same set bits should be contiguous in nature.Inputint arr[] = { 5, 8, 1, 2, 9, 12}Output − Maximum number of contiguous array elements with same number of set bits are − 3Explanation − we will calculate the binary digits for the elements of an array and calculate their set bits.arr[0] = 5 => 0101 => total set bits are -: 2 arr[1] = 8 => 1000 => total set ... Read More

Maximize Big When Both Big and Small Can Be Exchanged in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:32:31

200 Views

We are given a big object let’s say, ‘a’ and a small object let’s say, ‘b’. The choices for the object ‘a’ and ‘b’ depend upon the user. In the example below, we are taking objects to be toys which are big as well as small as per the size characteristics. The task is to calculate the maximum number of big toys that can be achieved by giving the small toys in return.Input − big_toys = 8, small_toys = 20, a = 6, b = 4Output − Maximize big when both big and small can be exchanged are − 11Explanation ... Read More

Maximum Factors Formed by Two Numbers in Python

Sunidhi Bansal
Updated on 03-Aug-2020 10:30:26

2K+ Views

We are given with an array of integer type elements and the task is to find the maximum factors formed by multiplying two numbers i.e. firstly we will multiply the numbers present in an array like calculating cross product secondly, we will calculate the factors of those numbers and check for the maximum factors amongst all.Inputint arr[] = {3, 2, 10}OutputMaximum factors formed by two numbers are: 8ExplanationCalculate the inner cross product i.e. 3 * 2 = 6, 3 * 10 = 30, 2 * 10 = 20Now calculate the factors for 6 -> 1, 2, 3, 6 ; 30 ... Read More

Count Identical Digits in Digital Clock using C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:29:04

355 Views

Suppose we have a digital clock of type HH:MM. Which shows the time in hours and minutes only. We are given a number of hours and minutes as input. The goal is to count the number of times all digits are the same. H=M.This happens 3 times a day, first at 00:00 midnight, then at 11:11 and last at 22:22. As time is represented in 24 hour format.InputInput: 12 hours 22 minutes.Output2Explanation − For times 00:00 and 11:11. Twice in 12 hours.InputInput: 48 hours 22 minutes.Output5Explanation − For times 00:00 and 11:11, 22:22 .Approach used in the below program is ... Read More

Advertisements