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....
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‘....
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....
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....
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...
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”....
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:...
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:...
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:...
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....
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....
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....