Swap all occurrences of two characters to get lexicographically smallest string
Given string str of lower case English alphabets. One can choose any two characters in the string and replace all the occurrences of the first character with the second character and replace all the occurrences of the second character with the first character. Find the lexicographically smallest string that can be obtained by doing this operation at most once. Examples:...
read more
Frequency of lexicographically Kth smallest character in the a string
Given a string S of length N and an integer K, the task is to find the frequency of the lexicographically Kth smallest character present in the given string....
read more
Lexicographically largest array possible from first N natural numbers such that every repetition is present at distance equal to its value from its previous occurrence
Given a positive integer N, the task is to construct the lexicographically largest array of size (2 * N – 1) comprising of first N natural numbers such that each element occurs twice except 1 and the repetition of X is exactly X distance apart in the constructed array....
read more
Find the lexicographical next balanced bracket sequence
Given a balanced bracket sequence as a string str containing character ‘(‘ or ‘)’, the task is to find the next lexicographical order balanced sequence if possible else print -1.Examples:...
read more
Lexicographically largest string possible for a given cost of appending characters
Given an integer W and an array a[] of size 26 where ai denotes the cost of using the ith alphabet, the task is to find lexicographically the largest string that can be generated for a cost, W....
read more
Largest lexicographic array with at-most K consecutive swaps
Given an array arr[], find the lexicographically largest array that can be obtained by performing at-most k consecutive swaps....
read more
Check if any permutation of a given string is lexicographically larger than the other given string
Given two strings str1 and str2 of same length N, the task is to check if there exists any permutation possible in any of the given strings, such that every character of one string is greater or equal to every character of the other string, at corresponding indices. Return true if permutation exists otherwise false....
read more
Lexicographically largest string using at most K swaps at same parity indices
Given string S and a positive integer K, the task is to find lexicographically the largest possible string using at most K swaps with the condition that the indices that are swapped must be either both odd or both even....
read more
Lexicographically smallest string which is not a subsequence of given string
Given a string S, the task is to find the string which is lexicographically smallest and not a subsequence of the given string S....
read more
Lexicographically smallest string formed by removing duplicates
Given a string S consisting of lowercase alphabets, the task is to find the lexicographically smallest string that can be obtained by removing duplicates from the given string S....
read more
Lexicographically n-th permutation of a string
Given a string of length m containing lowercase alphabets only. You have to find the n-th permutation of string lexicographically....
read more
Build lexicographically smallest String from two given Strings
Given two strings X and Y of lowercase letters, of length N and M respectively, the task is to build another string Z by performing two types of operations:...
read more