ShareChat Coding Question – Solved

10 Live
Subsequence Sort Given a binary string binary consisting of characters '0' and '1' only, perform the following 0 or more times. Β· Choose any subsequence, sort the subsequence, and replace the original subsequence with the sorted sequence. Next, there is an array of strings, arr, of length n, where each string has length / binary/ and consists of characters '0', '1' and '?'. Each '?' character can be replaced with either '0' or '1' . For each string in arr, after replacing each ?' character with either '0' or '1', determine if it is possible to rearrange binary using the operation described any number of times. If it is possible, store "YES" as the corresponding answer, otherwise store "NO", both without quotes. Note: Β· A string a is a subsequence of a string b obtained by deletion of some number (possibly, zero or all) of characters without changing the order of the remaining characters. Β· Each computation is independent of the others. That is, the string binary is in its original state at the beginning of each array element. Example Consider binary = "110100", and arr = ["?110?1","111 ??? "]. - arr[0] = "?110?1"can be converted to "011001"by appropriate replacement of ? characters. This string can be obtained from binary as follows: - Choose the subsequence of indices {0,2}, and sort this subsequence, binary becomes "011100". - Choose the subsequence of indices (3, 4, 5} and sort this subsequence, binary becomes "011001", which equals arr[0]. : The answer for this element is "YES". - It is not possible to convert string binary to arr[1] so the answer for this element is "NO". Return ["YES", "NO"], without quotes.

Asked in: ShareChat

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |