Programming Articles

Page 1758 of 2547

Maximum number of Strings with Common Prefix of length K

Shubham Vora
Shubham Vora
Updated on 31-Aug-2023 296 Views

In this problem, we need to count the maximum string having common prefix of length K. We can take prefix of length K from all strings and count maximum number of similar prefix using the map data structure. Also, we can use the Trie data structure to solve the problem. Problem statement - We have given an strs[] array containing multiple strings. We need to count the maximum number of strings containing a common prefix of length K. Sample Example Input strs = {"tutorialspoint", "tut", "abcd", "tumn", "tutorial", "PQR", "ttus", "tuto"}; K = 3; Output ...

Read More

Maximize value of Palindrome by rearranging characters of a Substring

Shubham Vora
Shubham Vora
Updated on 31-Aug-2023 359 Views

In this problem, we need to find the maximum palindromic string by rearranging the characters of any substring of the given string. We will use bitmasking to solve the largest palindromic substring. If any substring has bitmasking 0, it contains all characters even a number of times. So, we can generate a palindromic string using the characters of that substring, and we need to find the maximum palindromic string among them. Problem statement - We have given a string containing the N numeric characters. We need to find the maximum palindromic string by rearranging the characters 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
Prabhdeep Singh
Updated on 31-Aug-2023 208 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

Count of triplets in Binary String such that Bitwise AND of S[i], S[j] and S[j], S[k] are same

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

A binary string is a type of string which contains only binary characters that are '0' and '1'. We are given a binary string and have to find the triplets that fulfill the condition that the bitwise 'AND' of the first two characters is equal to the bitwise 'AND' of the last two characters. Mathematically: For 0

Read More

Maximum distance between Peaks in the given Linked List

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

A linked list is a linear data structure that stores the data in the nodes and each node contains the address of the next node to make the connection. A peak or the peak node is the node that is not present at the first or the last place and has a value strictly greater than both of the neighbors. We have to find the maximum distance between two consecutive peaks as there could be more than one peak available. Sample Examples Input Given Linked list: 1 -> 2 -> 3 -> 2 -> 7 -> 1 ...

Read More

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

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 212 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
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 243 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
Showing 17571–17580 of 25,466 articles
Advertisements