Found 34494 Articles for Programming

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

Prabhdeep Singh
Updated on 31-Aug-2023 11:45:28

56 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
Updated on 31-Aug-2023 11:32:33

41 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 last remaining element of the Array by selecting pairs such that arr[i] >= arr[j] and replace arr[i] with arr[i] – arr[j]

Prabhdeep Singh
Updated on 31-Aug-2023 12:20:15

68 Views

We are given an array of non-negative integers and we have to perform an operation of the given array any number of times possible so that we can choose any element of the array and can choose another element from the array that will be less than or equal to the current element and we will subtract it from the first element. After subtracting we will remove the first element if it becomes zero. After applying the above-described method any number of possible times we have to find the minimum possible element present in the array. ... Read More

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

Prabhdeep Singh
Updated on 31-Aug-2023 11:17:11

39 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
Updated on 31-Aug-2023 11:10:08

53 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
Updated on 31-Aug-2023 10:55:25

57 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

Count of setbits in bitwise OR of all K length substrings of given Binary String

Prabhdeep Singh
Updated on 31-Aug-2023 10:52:49

81 Views

Set bits are the bits in the binary representation of the number which are '1'. The binary representation of the number contains only two digits '1' and '0', also it may be present in the form of a string. We are given a string, the binary representation of a given number, and an integer k. We have to get all the substrings of the length k from the given string and take the bitwise OR of all of them and at last, we have to return the number of the set bits present in the final string. Sample ... Read More

Longest Common Subsequence with no Repeating Character

Prabhdeep Singh
Updated on 31-Aug-2023 10:31:28

121 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
Updated on 31-Aug-2023 10:28:01

48 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

Minimize cost by splitting the given Array into subsets of size K and adding the highest K/2 elements of each subset into the cost

Prabhdeep Singh
Updated on 31-Aug-2023 10:21:32

118 Views

Splitting the array means we have to divide the array and make subsets. Here in this problem, we have given an array of integers with size n and integer k and our goal is to calculate the lowest cost by splitting the whole given array into the subsets of size k and adding the highest k/2 element of each subset into the cost. NOTE: here we consider a ceiling of k/2. Let’s see examples with explanations below to understand the problem in a better way. Sample Example Input n: 4 array: [ 3, 4, 2, 1 ... Read More

Advertisements