GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday 20 July 2022

[Solution] Make Palindrome 2 CodeChef Solution




You are given a binary string S of length N. You want to obtain a palindrome from S by applying the following operation at most N2 times:

  • Choose an index i(1i|S|), delete the character Si from S and concatenate the remaining parts of the string. Here |S| denotes the current length of string S.

For example, if S= 11010, then applying the operation on index i=2 makes S= 1010.

Note that after each operation, the length of the string S decreases by one.

Find any palindrome you can obtain after the operations. It can be proved that it is always possible to obtain a palindrome from S under the given constraints.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

Here, N2 denotes floor division of the integer N by 2. For example, 52=282=4. A binary string is a string that consists of only the characters 0 and 1.

Input Format

  • The first line of input contains an integer T, denoting the number of test cases. The T test cases

  •  then follow:
  • The first line of each test case contains an integer N, denoting the length of the binary string S.
  • The second line of each test case contains the binary string S.

Output Format

For each test case, print on a separate line any palindromic string that can be obtained from S by applying the given operation at most N2 times.

Constraints

  • 1T1000
  • 1N100
  • S contains only the characters 0 and 1.

No comments:

Post a Comment