Find position of non-attacking Rooks in lexicographic order that can be placed on N*N chessboard
Given an integer N and an array arr[] of positions which denotes the positions of already placed non-attacking rooks, the task is to find the positions of non-attacking rooks in lexicographic order that can be placed on N*N chessboard.Movement of Rooks: Any rook can move horizontally or vertically by any number of unoccupied squares....
read more
Convert characters of string1 to characters present in string2 by incrementing or decrementing lexicographically
Given two strings A and B having lower case English alphabets, the task is to find the number of operations required to convert string A such that it only contains letters that are also in the string B where at each operation, the current character can be changed to either the next character or the previous character. Also, the next character after ‘z‘ is ‘a‘ and the previous character after ‘a‘ is ‘z‘....
read more
Find the light bulb with maximum glowing time
Given a string S consisting of N unique lowercase alphabets and an array arr[] of length N where character S[i] represents the bulb and arr[i] represents the time up to which the ith bulb glows, starting from the time arr[i – 1]. The task is to find the bulb with maximum glowing time. If there exists more than one bulb with the same maximum glowing time, print the lexicographically greater one....
read more
Lexicographically largest possible by merging two strings by adding one character at a time
Given two strings S and T, the task is to merge these two strings by adding one character at a time from the beginning of either string to form a resultant string. The resultant string should be lexicographically the largest string that can be formed by merging the strings S and T....
read more
Generating distinct subsequences of a given string in lexicographic order
Given a string s, make a list of all possible combinations of letters of a given string S. If there are two strings with the same set of characters, print the lexicographically smallest arrangement of the two stringsFor string abc, the list in lexicographic order subsequences are, a ab abc ac b bc c...
read more
Lexicographically smallest binary string formed by flipping bits at indices not divisible K1 or K2 such that count of 1s is always greater than 0s from left
Given a binary string S(1-based indexing) of size N, and two positive integers K1 and K2, the task is to find the lexicographically smallest string by flipping the characters at indices that are not divisible by either K1 or K2 such that the count of 1s till every possible index is always greater than the count of 0s. If it is not possible to form such string, the print “-1”....
read more
Find the lexicographically smallest sequence which can be formed by re-arranging elements of second array
Given two arrays A and B of N integers. Reorder the elements of B in itself in such a way that the sequence formed by (A[i] + B[i]) % N after re-ordering is the smallest lexicographically. The task is to print the lexicographically smallest sequence possible. Note: The array elements are in range [0, n).Examples:...
read more
Lexicographically smallest array formed by at most one swap for every pair of adjacent indices
Given an array A[] of length N, the task is to find lexicographically smallest array by swapping adjacent elements for each index atmost once. Thus, for any index:...
read more
Lexicographically smallest and largest string possible via Transitive mapping
Given two strings str1 and str2 containing lowercase letters. The task is to convert the given string str3 into lexicographically smallest and largest string that can be formed under the following conditions:...
read more
Construct lexicographically smallest Binary array of size N with A 0s and X inversion count
Given three numbers N, A, and X, the task is to construct the lexicographically smallest binary array of size N, containing A 0s and having an inversion count of X....
read more
Find the winner of the game to build the lexicographically smaller string
Two players are playing a game where string str is given. The first player can take the characters at even indices and the second player can take the characters at odd indices. The player which can build the lexicographically smaller string than the other player wins the game. Print the winner of the game, either player A, B or print Tie if it’s a tie....
read more
Find Mth lexicographically smallest Binary String with no two adjacent 1
Given two integers N and M, the task is to find the Mth lexicographically smallest binary string (have only characters 1 and 0) of length N where there cannot be two consecutive 1s....
read more