Found 1862 Articles for Data Structure

C++ Program to Find Mth element after K Right Rotations of an Array

Prabhdeep Singh
Updated on 31-Aug-2023 12:03:45

58 Views

Right Rotations means we have to shift each element towards the right as the 0th index element shift to the 1st index, the 1st index element shift to the 2nd index, ..., and the last element shift to the 0th index. Here we have given an array of integers of size n, integer m, and integer k. Our task is to find the mth element after k right rotations of an array. Here are some examples and explanations to help you understand the issue. Sample Examples Input Array: [ 1, 3, 2, 5, 6, 7 ], k: ... Read More

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

Prabhdeep Singh
Updated on 31-Aug-2023 12:01:24

88 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
Updated on 31-Aug-2023 11:59:45

74 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
Updated on 31-Aug-2023 11:51:21

127 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
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

66 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

51 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

56 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

Advertisements