{"id":"2ece2109-705d-4375-b5f1-ff2a207fd159","name":"Maximum Difference Of Zeros And Ones In Binary String","description":"1. You are given a string containing only 0's and 1's.\r\n2. You have to find the length of substring which is having maximum difference of number of 0s and number of 1s i.e (Number of 0's - Number of 1's).\r\n3. If there are all 1's present in the given string, then print '-1'. ","inputFormat":"A Binary String","outputFormat":"A number ","constraints":"1 <= length of string <= 10^5","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str) {\r\n\t\t// write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString string = scn.next();\r\n\t\tSystem.out.println(solution(str));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"11000010001","sampleOutput":"6\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"0be128f4-0d29-4fa7-aad5-e3bcfb61da02","name":"Maximum Difference Of Zeros And Ones In Binary String","slug":"maximum-difference-of-zeros-and-ones-in-binary-string","type":1}],"next":{"id":"598d4e68-a6a8-40e1-aed0-d92667be8daa","name":"Maximum difference of zeroes and ones in binary string MCQ","type":0,"slug":"maximum-difference-of-zeroes-and-ones-in-binary-string-mcq"},"prev":{"id":"c4cc35bf-0787-48f1-b2f3-102509b69d34","name":"Distinct Transformations","type":3,"slug":"distinct-transformations"}}}

Maximum Difference Of Zeros And Ones In Binary String

1. You are given a string containing only 0's and 1's. 2. You have to find the length of substring which is having maximum difference of number of 0s and number of 1s i.e (Number of 0's - Number of 1's). 3. If there are all 1's present in the given string, then print '-1'.

{"id":"2ece2109-705d-4375-b5f1-ff2a207fd159","name":"Maximum Difference Of Zeros And Ones In Binary String","description":"1. You are given a string containing only 0's and 1's.\r\n2. You have to find the length of substring which is having maximum difference of number of 0s and number of 1s i.e (Number of 0's - Number of 1's).\r\n3. If there are all 1's present in the given string, then print '-1'. ","inputFormat":"A Binary String","outputFormat":"A number ","constraints":"1 <= length of string <= 10^5","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str) {\r\n\t\t// write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString string = scn.next();\r\n\t\tSystem.out.println(solution(str));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"11000010001","sampleOutput":"6\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"0be128f4-0d29-4fa7-aad5-e3bcfb61da02","name":"Maximum Difference Of Zeros And Ones In Binary String","slug":"maximum-difference-of-zeros-and-ones-in-binary-string","type":1}],"next":{"id":"598d4e68-a6a8-40e1-aed0-d92667be8daa","name":"Maximum difference of zeroes and ones in binary string MCQ","type":0,"slug":"maximum-difference-of-zeroes-and-ones-in-binary-string-mcq"},"prev":{"id":"c4cc35bf-0787-48f1-b2f3-102509b69d34","name":"Distinct Transformations","type":3,"slug":"distinct-transformations"}}}
plane

Editor


Loading...

Maximum Difference Of Zeros And Ones In Binary String

easy

1. You are given a string containing only 0's and 1's. 2. You have to find the length of substring which is having maximum difference of number of 0s and number of 1s i.e (Number of 0's - Number of 1's). 3. If there are all 1's present in the given string, then print '-1'.

Constraints

1 <= length of string <= 10^5

Format

Input

A Binary String

Output

A number

Example

Sample Input

11000010001

Sample Output

6

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode