{"id":37,"date":"2019-02-05T19:08:27","date_gmt":"2019-02-05T19:08:27","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/coding\/?p=37"},"modified":"2019-02-05T19:08:27","modified_gmt":"2019-02-05T19:08:27","slug":"question-4-find-duplicate-element-in-array","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/","title":{"rendered":"Question 4: Find Duplicate Element in Array"},"content":{"rendered":"<h4><strong>Question 4<\/strong><\/h4>\n<p>You are given an array of size n. One of the elements of the array appears twice in the array. Every other element appears once. You need to find the duplicate element.<\/p>\n<p>For example<\/p>\n<p><strong>Input:<\/strong> {3, 6, 9, 0, 4, 7, 6}<\/p>\n<p><strong>Output:<\/strong> The duplicate is 6<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Solution 1: Brute Force Approach (Inefficient, O(n<sup>2<\/sup>))<\/strong><\/h4>\n<p>In this approach, you iterate through the array and compare each element with every other element in the array until you find a match.<\/p>\n<p>The Java code is given below<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #333333;\">\/*<\/span>\r\n <span style=\"color: #333333;\">*<\/span> Find duplicate <span style=\"color: #000000; font-weight: bold;\">in<\/span> array using brute force\r\n <span style=\"color: #333333;\">*<\/span> Written by Kindson the Genius\r\n <span style=\"color: #333333;\">*\/<\/span>\r\npublic <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">FindDuplicateElement1<\/span> {\r\n\t\r\n\tpublic static void findDuplicateElement(<span style=\"color: #007020;\">int<\/span>[] A) {\r\n\t\t\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span>(<span style=\"color: #007020;\">int<\/span> i <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>; i <span style=\"color: #333333;\">&lt;<\/span> A<span style=\"color: #333333;\">.<\/span>length<span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span>; i<span style=\"color: #333333;\">++<\/span>) {\r\n\t\t\t\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span>(<span style=\"color: #007020;\">int<\/span> j <span style=\"color: #333333;\">=<\/span> i<span style=\"color: #333333;\">+<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span>; j <span style=\"color: #333333;\">&lt;<\/span> A<span style=\"color: #333333;\">.<\/span>length; j<span style=\"color: #333333;\">++<\/span> ) {\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span>(A[i] <span style=\"color: #333333;\">==<\/span> A[j]) {\r\n\t\t\t\t\tSystem<span style=\"color: #333333;\">.<\/span>out<span style=\"color: #333333;\">.<\/span>println(<span style=\"background-color: #fff0f0;\">\"Duplicate at \"<\/span> <span style=\"color: #333333;\">+<\/span> i <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" and \"<\/span> <span style=\"color: #333333;\">+<\/span> j);\r\n\t\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span>;\r\n\t\t\t\t}\r\n\t\t\t}\t\t\t\r\n\t\t}<span style=\"color: #333333;\">\/\/<\/span>end of <span style=\"color: #008800; font-weight: bold;\">for<\/span> loop\t\t\r\n\t\tSystem<span style=\"color: #333333;\">.<\/span>out<span style=\"color: #333333;\">.<\/span>println(<span style=\"background-color: #fff0f0;\">\"No duplicates found\"<\/span>);\t\t\r\n\t}<span style=\"color: #333333;\">\/\/<\/span>end of function\r\n\r\n\t\r\n\t<span style=\"color: #333333;\">\/\/<\/span>Main method to test the function\r\n\tpublic static void main(String[] args) {\r\n\t\t<span style=\"color: #007020;\">int<\/span> ar[] <span style=\"color: #333333;\">=<\/span> {<span style=\"color: #0000dd; font-weight: bold;\">4<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">4<\/span>};\r\n\t\tfindDuplicateElement(ar);\r\n\t}\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Solution 2 &#8211; Using Hashing &#8211; O(n)<\/strong><\/h4>\n<p>In this solution, we iterate through the array once. For each iteration, we check if the value is in the hash table. If yes, then it&#8217;s a duplicate. If not, then we insert it into the hash table.<\/p>\n<p>The Java code is given below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.HashMap<\/span>;\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.Map<\/span>;\r\n\r\n<span style=\"color: #333333;\">\/*<\/span>\r\n <span style=\"color: #333333;\">*<\/span> Find duplicate <span style=\"color: #000000; font-weight: bold;\">in<\/span> array using hashing\r\n <span style=\"color: #333333;\">*<\/span> Written by Kindson the Genius\r\n <span style=\"color: #333333;\">*\/<\/span>\r\n\r\npublic <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">FindDuplicateElement<\/span> {\r\n\t\r\n\t<span style=\"color: #333333;\">\/\/<\/span>Return indexes of duplicate\r\n\tpublic static void findDuplicateElements(<span style=\"color: #007020;\">int<\/span> A[]) {\r\n\t\t\r\n\t\tMap<span style=\"color: #333333;\">&lt;<\/span>Integer,Integer<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #007020;\">map<\/span> <span style=\"color: #333333;\">=<\/span> new HashMap<span style=\"color: #333333;\">&lt;<\/span>Integer, Integer<span style=\"color: #333333;\">&gt;<\/span>();\r\n\t\t\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span>(<span style=\"color: #007020;\">int<\/span> i <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>; i <span style=\"color: #333333;\">&lt;<\/span> A<span style=\"color: #333333;\">.<\/span>length; i<span style=\"color: #333333;\">++<\/span>) {\r\n\t\t\t\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span>(<span style=\"color: #007020;\">map<\/span><span style=\"color: #333333;\">.<\/span>containsKey(A[i])) {\r\n\t\t\t\tSystem<span style=\"color: #333333;\">.<\/span>out<span style=\"color: #333333;\">.<\/span>println(<span style=\"background-color: #fff0f0;\">\"Duplicates at \"<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">map<\/span><span style=\"color: #333333;\">.<\/span>get(A[i]) <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" and \"<\/span> <span style=\"color: #333333;\">+<\/span> i);\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span>;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t<span style=\"color: #007020;\">map<\/span><span style=\"color: #333333;\">.<\/span>put(A[i], i);\r\n\t\t}\r\n\t\t\r\n\t\tSystem<span style=\"color: #333333;\">.<\/span>out<span style=\"color: #333333;\">.<\/span>println(<span style=\"background-color: #fff0f0;\">\"No duplicate found\"<\/span>);\r\n\t}\r\n\t\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\t<span style=\"color: #007020;\">int<\/span>[] ar <span style=\"color: #333333;\">=<\/span> {<span style=\"color: #0000dd; font-weight: bold;\">5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">7<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">2<\/span>};\r\n\t\tfindDuplicateElements(ar);\r\n\t}\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Solution 3 &#8211; Using Sorting<\/strong><\/h4>\n<p>In this approach, we first sort the array. Sorting takes logarithmic time. Then the duplicate element would then be side by side.<\/p>\n<p>Then we loop through the array comparing each element with the immediate next element. Once there is a match then we return. But the challenge with this approach is that the index of the elements after sorting would change. So we only return the duplicate element and not the index.<\/p>\n<p>The Java code is given below:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #333333;\">\/*<\/span>\r\n <span style=\"color: #333333;\">*<\/span> Find duplicate <span style=\"color: #000000; font-weight: bold;\">in<\/span> array using sorting\r\n <span style=\"color: #333333;\">*<\/span> Written by Kindson the Genius\r\n <span style=\"color: #333333;\">*\/<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.Arrays<\/span>;\r\n\r\npublic <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">FindDuplicateElement2<\/span> {\r\n\t\r\n\tpublic static void findDuplicateElement(<span style=\"color: #007020;\">int<\/span> A[]) {\r\n\t\t\r\n\t\t<span style=\"color: #333333;\">\/\/<\/span>First sort the array\r\n\t\tArrays<span style=\"color: #333333;\">.<\/span>sort(A);\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span>(A<span style=\"color: #333333;\">.<\/span>length <span style=\"color: #333333;\">&lt;=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>) {\r\n\t\t\tSystem<span style=\"color: #333333;\">.<\/span>out<span style=\"color: #333333;\">.<\/span>println(<span style=\"background-color: #fff0f0;\">\"Unable to proceed\"<\/span>);\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span>;\r\n\t\t}\r\n\t\t\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span>(<span style=\"color: #007020;\">int<\/span> i <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>; i <span style=\"color: #333333;\">&lt;<\/span> A<span style=\"color: #333333;\">.<\/span>length<span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span>; i<span style=\"color: #333333;\">++<\/span>) {\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span>(A[i] <span style=\"color: #333333;\">==<\/span> A[i<span style=\"color: #333333;\">+<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span>]) {\r\n\t\t\t\tSystem<span style=\"color: #333333;\">.<\/span>out<span style=\"color: #333333;\">.<\/span>println(<span style=\"background-color: #fff0f0;\">\"Duplicate element is \"<\/span> <span style=\"color: #333333;\">+<\/span> A[i]);\r\n\t\t\t\t\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span>;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tSystem<span style=\"color: #333333;\">.<\/span>out<span style=\"color: #333333;\">.<\/span>println(<span style=\"background-color: #fff0f0;\">\"No duplicated found\"<\/span>);\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t<span style=\"color: #007020;\">int<\/span> ar[] <span style=\"color: #333333;\">=<\/span> {<span style=\"color: #0000dd; font-weight: bold;\">3<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">4<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>};\r\n\t\tfindDuplicateElement(ar);\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Question 4 You are given an array of size n. One of the elements of the array appears twice in the array. Every other element &hellip; <\/p>\n","protected":false},"author":395,"featured_media":39,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,2,3],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-array","category-coding-challenge","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Question 4: Find Duplicate Element in Array - Coding Challenge<\/title>\n<meta name=\"description\" content=\"You will learn three different methods of finding duplicate elements in an array: brute force approach, sorting and hashing\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Question 4: Find Duplicate Element in Array - Coding Challenge\" \/>\n<meta property=\"og:description\" content=\"You will learn three different methods of finding duplicate elements in an array: brute force approach, sorting and hashing\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/\" \/>\n<meta property=\"og:site_name\" content=\"Coding Challenge\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-05T19:08:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/coding\/wp-content\/uploads\/sites\/4\/2019\/02\/Find-Duplicate-Element-in-an-Array.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"927\" \/>\n\t<meta property=\"og:image:height\" content=\"495\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"headline\":\"Question 4: Find Duplicate Element in Array\",\"datePublished\":\"2019-02-05T19:08:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/\"},\"wordCount\":225,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/wp-content\\\/uploads\\\/sites\\\/4\\\/2019\\\/02\\\/Find-Duplicate-Element-in-an-Array.jpg\",\"articleSection\":[\"Array\",\"Coding Challenge\",\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/\",\"name\":\"Question 4: Find Duplicate Element in Array - Coding Challenge\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/wp-content\\\/uploads\\\/sites\\\/4\\\/2019\\\/02\\\/Find-Duplicate-Element-in-an-Array.jpg\",\"datePublished\":\"2019-02-05T19:08:27+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"description\":\"You will learn three different methods of finding duplicate elements in an array: brute force approach, sorting and hashing\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/wp-content\\\/uploads\\\/sites\\\/4\\\/2019\\\/02\\\/Find-Duplicate-Element-in-an-Array.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/wp-content\\\/uploads\\\/sites\\\/4\\\/2019\\\/02\\\/Find-Duplicate-Element-in-an-Array.jpg\",\"width\":927,\"height\":495,\"caption\":\"Find duplicate element in an array\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/question-4-find-duplicate-element-in-array\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Question 4: Find Duplicate Element in Array\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/\",\"name\":\"Coding Challenge\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/author\\\/kindsonthegenius-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Question 4: Find Duplicate Element in Array - Coding Challenge","description":"You will learn three different methods of finding duplicate elements in an array: brute force approach, sorting and hashing","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/","og_locale":"en_US","og_type":"article","og_title":"Question 4: Find Duplicate Element in Array - Coding Challenge","og_description":"You will learn three different methods of finding duplicate elements in an array: brute force approach, sorting and hashing","og_url":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/","og_site_name":"Coding Challenge","article_published_time":"2019-02-05T19:08:27+00:00","og_image":[{"width":927,"height":495,"url":"https:\/\/www.kindsonthegenius.com\/coding\/wp-content\/uploads\/sites\/4\/2019\/02\/Find-Duplicate-Element-in-an-Array.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/coding\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"headline":"Question 4: Find Duplicate Element in Array","datePublished":"2019-02-05T19:08:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/"},"wordCount":225,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/coding\/wp-content\/uploads\/sites\/4\/2019\/02\/Find-Duplicate-Element-in-an-Array.jpg","articleSection":["Array","Coding Challenge","Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/","url":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/","name":"Question 4: Find Duplicate Element in Array - Coding Challenge","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/coding\/wp-content\/uploads\/sites\/4\/2019\/02\/Find-Duplicate-Element-in-an-Array.jpg","datePublished":"2019-02-05T19:08:27+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"description":"You will learn three different methods of finding duplicate elements in an array: brute force approach, sorting and hashing","breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/coding\/wp-content\/uploads\/sites\/4\/2019\/02\/Find-Duplicate-Element-in-an-Array.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/coding\/wp-content\/uploads\/sites\/4\/2019\/02\/Find-Duplicate-Element-in-an-Array.jpg","width":927,"height":495,"caption":"Find duplicate element in an array"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/coding\/question-4-find-duplicate-element-in-array\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/coding\/"},{"@type":"ListItem","position":2,"name":"Question 4: Find Duplicate Element in Array"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/coding\/#website","url":"https:\/\/www.kindsonthegenius.com\/coding\/","name":"Coding Challenge","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/coding\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/coding\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/coding\/author\/kindsonthegenius-2\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":2,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":40,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/posts\/37\/revisions\/40"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/media\/39"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}