{"id":381,"date":"2023-01-18T15:06:33","date_gmt":"2023-01-18T15:06:33","guid":{"rendered":"https:\/\/premsvmm.com\/?p=381"},"modified":"2023-01-18T15:06:51","modified_gmt":"2023-01-18T15:06:51","slug":"first-non-distinct-value-in-an-array","status":"publish","type":"post","link":"https:\/\/premsvmm.com\/index.php\/2023\/01\/18\/first-non-distinct-value-in-an-array\/","title":{"rendered":"First Non Distinct value in an Array"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">Find the non-distinct value in a given array<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Input : {1,1,2,2,3,4,4}<\/p>\n\n\n\n<p>Output : 3<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Code<\/h4>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;darcula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">package wordpress;\n\nimport java.util.Hashtable;\n\npublic class Nondistinct {\n\n    private static Integer firstNonDistinct(Integer[] input) {\n        Hashtable&lt;Integer, Integer&gt; hash = new Hashtable&lt;&gt;();\n        for (Integer key : input) {\n            if (hash.containsKey(key)) {\n                int count = hash.get(key);\n                hash.put(key, ++count);\n            } else {\n                hash.put(key, 1);\n            }\n        }\n        for (Integer key : input) {\n            if (hash.get(key) == 1)\n                return key;\n        }\n        return 0;\n    }\n\n    public static void main(String[] args) {\n        System.out.println(firstNonDistinct(new Integer[]{1, 1, 2, 2, 3, 4, 4})); \/\/ 3\n        System.out.println(firstNonDistinct(new Integer[]{1, 1, 2, 2, 3,3, 4, 4})); \/\/ 0\n        System.out.println(firstNonDistinct(new Integer[]{1,2,3,4})); \/\/ 1\n        System.out.println(firstNonDistinct(new Integer[]{-1,0,0,1,1})); \/\/ -1\n    }\n}\n<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Find the non-distinct value in a given array Input : {1,1,2,2,3,4,4} Output : 3 Code<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[10],"tags":[11],"_links":{"self":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/381"}],"collection":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":1,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/381\/revisions\/382"}],"wp:attachment":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}