{"id":"4c32a901-e5ed-486f-8cca-4fbc14cf300f","name":"Find Transition Point","description":"1. Given a sorted array containing only 0s and 1s, find the transition point.\r\n2. Transition Point is defined as 1's starting point.\r\n3. If there is no transition point, return -1.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;= 500000\r\n0 &lt;= arr[i] &lt;= 1","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n\nint findTransition(vector<int> &arr){\n // write your code here\n return 0;\n}\n\nint main() {\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n for(int i = 0; i < arr.size(); i++){\n cin >> arr[i];\n }\n \n cout << findTransition(arr) << endl;\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int findTransition(int[]arr) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(findTransition(arr));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n0 0 0 0 1 1","sampleOutput":"4","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":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"c16015fb-dc94-4b52-9b31-1a1c0d3808fd","name":"Find Transition Point","slug":"find-transition-point","type":1}],"next":{"id":"58bfbdbd-f1ff-4d8d-933a-94e23f5b3744","name":"Find Transition Point","type":3,"slug":"find-transition-point"},"prev":{"id":"ca712e25-1372-46ef-b802-1d30df973a9d","name":"Distinct Absolute Array Elements MCQ","type":0,"slug":"distinct-absolute-array-elements-mcq"}}}

Find Transition Point

1. Given a sorted array containing only 0s and 1s, find the transition point. 2. Transition Point is defined as 1's starting point. 3. If there is no transition point, return -1.

{"id":"4c32a901-e5ed-486f-8cca-4fbc14cf300f","name":"Find Transition Point","description":"1. Given a sorted array containing only 0s and 1s, find the transition point.\r\n2. Transition Point is defined as 1's starting point.\r\n3. If there is no transition point, return -1.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;= 500000\r\n0 &lt;= arr[i] &lt;= 1","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n\nint findTransition(vector<int> &arr){\n // write your code here\n return 0;\n}\n\nint main() {\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n for(int i = 0; i < arr.size(); i++){\n cin >> arr[i];\n }\n \n cout << findTransition(arr) << endl;\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int findTransition(int[]arr) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(findTransition(arr));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n0 0 0 0 1 1","sampleOutput":"4","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":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"c16015fb-dc94-4b52-9b31-1a1c0d3808fd","name":"Find Transition Point","slug":"find-transition-point","type":1}],"next":{"id":"58bfbdbd-f1ff-4d8d-933a-94e23f5b3744","name":"Find Transition Point","type":3,"slug":"find-transition-point"},"prev":{"id":"ca712e25-1372-46ef-b802-1d30df973a9d","name":"Distinct Absolute Array Elements MCQ","type":0,"slug":"distinct-absolute-array-elements-mcq"}}}
plane

Editor


Loading...

Find Transition Point

easy

1. Given a sorted array containing only 0s and 1s, find the transition point. 2. Transition Point is defined as 1's starting point. 3. If there is no transition point, return -1.

Constraints

1 <= N <= 500000 0 <= arr[i] <= 1

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

6 0 0 0 0 1 1

Sample Output

4

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode