Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Find the maximum possible length of a symmetric fragment which can be obtained after replacing question marks in a given string with <

Find the maximum possible length of a symmetric fragment which can be obtained after replacing question marks in a given string with "<" or ">".
Task description
A string made of an even number of characters ("<" and/or ">") is called symmetric if all characters in its first half are "<" and all characters in its second half are ">". Examples of symmetric strings are: ""(empty string),"<>","<<>>","<<<>>>", etc.
Write a function:
function solution(S);
that, given a string S made of N characters ("<",">" and/or "?")", returns the length of the longest symmetric substring that can be obtained after replacing question marks with "<" or ">" characters.
Examples:
1. For S ="<>>", after replacing all question marks with "<", the string "<><<<>>" is obtained. Its longest symmetric substring is "<<>>", so the function should return 4.
2. For S ="??????", the optimal option is to replace the first three question marks with "<" and the next three question marks with ">", thus obtaining the string "<<<>>>". The function should return 6.
3. For S ="<' and/or '?'.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions

Question

2. Why do you think this approach has been adopted?

Answered: 1 week ago