SOLVE

LATER

Save the Kidney

Problem

Editorial

Analytics

It is Valentine's Day and Rishabh's girlfriend has asked Rishabh to buy her the new iPhone 8 as a gift. Rishabh is a poor guy and doesn't have enough money to buy the iPhone, at the same time he does not want to disappoint his girlfriend. In order to keep his girlfriend happy, he decides to sell one of his kidneys to get the money for the iPhone.

**SAVE ME!!!**

But he has a helpful friend - Viral, so he asks him for money so that he would not have to sell his kidney. Viral, being an algorithm lover agrees to give Rishabh the money only if he solves the following problem- You are given a string

smade up of0s,1sandxsonly. In place of'x', you can fill in any single character -'0'or'1'. Print the length of a sub-string ofs, such that after filling in all thexswith either'0'or'1', the number of0sis equal to the number of1sin that sub-string and the sub-string is ofmaximum length. Note that it isNOTnecessary that allxsshould have the same value. You can replace different xs with different values(either'1'or'0'only).If there is no such sub-string having equal number of 0s and 1s after replacing all the xs with 0 or 1, then print -1.Since Rishabh is from EEE, he is not very good at coding and needs your help to solve the problem. Can you help him and save his kidney ?

REMEMBER: A sub-string is a contiguous part of the original string. The sub-string is itself a string.

CONSTRAINTS:1 <= n <= 100000

0 <= no. of x <= 9

INPUT:The input consists of

twolines.The first line contains a single integer

ndenoting the length of the string.The second line consists of a single string of length

n, made up of0,1andxonly.

OUTPUT:If a sub-string having equal number of

0sand1s(after replacing allxswith either0or1) doesNOTexist, then, print-1.Otherwise, print the

maximum lengthof sub-string ofssuch that number of0sequals the number of1s(after replacing allxswith either0or1).

:Problem AuthorViral Mehta

Explanation

If you replace one of the xs with 1 and the other with 0, then the sub-string from index 1 to index 6 (indexing starts from 1) has equal number of 0s and 1s.

Time Limit:
2.0 sec(s)
for each input file.

Memory Limit:
512 MB

Source Limit:
1025 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
C,
C++,
C++14,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
Julia,
Kotlin,
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Swift,
Visual Basic

Initializing Code Editor...

{"f9a9a49": "/pagelets/show-submission/algorithm/save-rishabhs-kidney/", "ee0701c": "/pagelets/suggested-problems/algorithm/save-rishabhs-kidney/", "8c0078c": "/pagelets/problem-author-tester/algorithm/save-rishabhs-kidney/", "12c6f4b": "/pagelets/problems-hint/algorithm/save-rishabhs-kidney/", "cfe1237": "/pagelets/recommended-problems/algorithm/save-rishabhs-kidney/"}

realtime.hackerearth.com

80

98f0bfdd3ba15eed3958333e454c012a4801e68c

58a29e5cae2309f04b28

/realtime/pusher/auth/