{"id":"80a75505-f47d-4ab2-bb43-692753c2308d","name":"Find The Element That Appears Once In Sorted Array ","description":"Given a sorted array arr[] of size N. Find the element that appears only once in the array. All other elements appear exactly twice. \r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"10^5 &lt;= N &lt;= 10^5\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint findSingleElement(vector<int> &arr) {\n //write your code here\n \n}\n\nint main(){\n //input work\n int n;\n cin>>n;\n vector<int> arr(n);\n\n for (int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n\n int ans = findSingleElement(arr);\n cout<<ans;\n }"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int findSingleElement(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 int ans = findSingleElement(arr);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"11\r\n1 1 2 2 4 4 7 7 8 10 10","sampleOutput":"8","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":"79fad7ab-2970-4c90-83d7-811014e9d2ab","name":"Find The Element That Appears Once In Sorted Array ","slug":"find-the-element-that-appears-once-in-sorted-array","type":1}],"next":{"id":"e16b271b-0e61-4b3e-aeeb-19a3b392006c","name":"Find The Element That Appears Once In Sorted Array","type":3,"slug":"find-the-element-that-appears-once-in-sorted-array"},"prev":{"id":"38029e74-726c-4f41-8d4a-c499bbced22d","name":"Find Transition Point MCQ","type":0,"slug":"find-transition-point-mcq"}}}

Find The Element That Appears Once In Sorted Array

Given a sorted array arr[] of size N. Find the element that appears only once in the array. All other elements appear exactly twice.

{"id":"80a75505-f47d-4ab2-bb43-692753c2308d","name":"Find The Element That Appears Once In Sorted Array ","description":"Given a sorted array arr[] of size N. Find the element that appears only once in the array. All other elements appear exactly twice. \r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"10^5 &lt;= N &lt;= 10^5\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint findSingleElement(vector<int> &arr) {\n //write your code here\n \n}\n\nint main(){\n //input work\n int n;\n cin>>n;\n vector<int> arr(n);\n\n for (int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n\n int ans = findSingleElement(arr);\n cout<<ans;\n }"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int findSingleElement(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 int ans = findSingleElement(arr);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"11\r\n1 1 2 2 4 4 7 7 8 10 10","sampleOutput":"8","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":"79fad7ab-2970-4c90-83d7-811014e9d2ab","name":"Find The Element That Appears Once In Sorted Array ","slug":"find-the-element-that-appears-once-in-sorted-array","type":1}],"next":{"id":"e16b271b-0e61-4b3e-aeeb-19a3b392006c","name":"Find The Element That Appears Once In Sorted Array","type":3,"slug":"find-the-element-that-appears-once-in-sorted-array"},"prev":{"id":"38029e74-726c-4f41-8d4a-c499bbced22d","name":"Find Transition Point MCQ","type":0,"slug":"find-transition-point-mcq"}}}
plane

Editor


Loading...

Find The Element That Appears Once In Sorted Array

medium

Given a sorted array arr[] of size N. Find the element that appears only once in the array. All other elements appear exactly twice.

Constraints

10^5 <= N <= 10^5

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

11 1 1 2 2 4 4 7 7 8 10 10

Sample Output

8

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode