C++ Articles

Page 375 of 597

Count elements in Array having strictly smaller and strictly greater elements present

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 369 Views

A number is strictly a smaller element means the number should be less than by a minimum difference is 1 and similarly strictly greater element means the number should be greater than by a minimum of difference 1. Here we have given an array of integers of size n and we have to return the count of elements in the array having strictly smaller and strictly greater elements present. Let's see examples with explanations below to understand the problem in a better way. Sample Examples Input N = 5 Array: [ 3, 2, 1, 4, 5 ] ...

Read More

Minimize operations to convert K from 0 to B by adding 1 or A * 10^c in each step

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 244 Views

We are given an integer B and A, and we have to convert the number K from 0 to exactly B by applying the given operations in the minimum steps. We can increase the current number K by 1 i.e. K = K + 1 We can add the product of the number A with any power of 10 to the number K i.e. K = K + A * 10^p, where p is any non-negative number. Sample Examples ...

Read More

Minimize cost to reduce Array if for choosing every 2 elements, 3rd one is chosen for free

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 306 Views

We are given an array it this problem and we have to remove all the elements of the array with the minimum cost required. We have to remove two elements at a time and add them to the total cost. Also, we can remove the third number without any cost if we remove two elements and the third element's value is at most equal to the minimum of them. Also, it is given that the given array will be of a size greater than 1. Sample Examples Input int arr[] = {7, 6, 5, 2, 9, ...

Read More

Find the index at which bit must be set to maximize the distance between the next set bit

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 226 Views

We are given an array that contains the binary numbers that are '0', and '1' only. We have to make a one-bit set of the given array which was earlier not the set bit (there will be at least a bit present in the given array which will not be a set bit) to set bit such that the number of indexes present in between the set bits of the final array will be at the maximum distance possible. Sample Examples Input int arr[] = {1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, ...

Read More

Find the winner of the game where X picks 1, then Y picks 2, then X picks 3, and so on

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 172 Views

There are two players, X and Y, who are playing a game. X will start the first and can pick 1 stone from the set of an unlimited number of stones after that Y will start and can pick the 2 stones, then X will pick 3, and so on the game will go alternatively until the sum of the total stones picked by X is less than or equal to the given number A or the sum of total stones picked by Y is less than or equal to another given number B. If the current sum of any ...

Read More

Minimize the count of peaks and troughs in the given Array after at most one replacement

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 203 Views

Peaks are defined as the point or index in the array where are both left and right sides values are smaller than the value of that index. And Troughs are defined as the point or index of the array where are both left and right sides values are greater than the value of that index. In this problem, we have given an array 'array' of size n of integers. Our task is to minimize or reduce the count of peaks and troughs of the given array by performing an operation. Operation is that we can replace at most one value of the ...

Read More

Check if string A can be converted to string B by changing A[i] to A[i+1] or A[i]..A[i+K-1] to A[i]+1 each

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 362 Views

We are given two strings and we have to check if it is possible to convert the first string to another by performing any number of times a particular given task. The tasks that can be performed on the given first string only and the tasks are: Choose any index i such that i < length(A) -1 and swap ith character with the next character. We are given an integer k and we can choose any consecutive k indexes of the first string only if they are ...

Read More

Find Binary String of size at most 3N containing at least 2 given strings of size 2N as subsequences

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 254 Views

We are given three strings of equal size equal to 2*N, where N is an integer. We have to create a string of the size 3*N and at least two strings from the given strings be the subsequence of it. Also, the given strings are binary strings which means they only contain two different characters '0' and '1'. We will implement a code by traversing over the string and getting the frequency of the zeros and ones. Sample Examples Input string str1 = “11”; string str2 = “10”; string str3 = “10”; Output 110 ...

Read More

Longest Common Subsequence with no Repeating Character

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 411 Views

In a string, a subsequence is a string that can be formed by deleting some character from it which means it contains some character from the string may be all or none and all will be present in the same order of the string. Among two strings we have to find the longest common subsequence that will not contain any repeating characters. Sample Examples Input string str1 = "aabcadjmuorrrcc" string str2 = "adbcwcadjomrorlc" Output The length of the longest common subsequence is: 8 Explanation: In the above-given strings, we have the largest ...

Read More

Capitalize 1st character of all words having at least K characters

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 227 Views

In the English language while writing a sentence we need to start with the capital character and for any name of the city/person, etc we begin with the capital letter. Here in this problem, we are given a string and a number and we have to update the first character of all the words of the given string if their size is not less than k. Also, if the size of the words is more than k and their first character is already capitalized then we will leave it as it is. Sample Examples Input string str ...

Read More
Showing 3741–3750 of 5,962 articles
« Prev 1 373 374 375 376 377 597 Next »
Advertisements