<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":356,"date":"2021-07-12T21:58:14","date_gmt":"2021-07-12T21:58:14","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=356"},"modified":"2021-08-24T06:32:47","modified_gmt":"2021-08-24T06:32:47","slug":"given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/","title":{"rendered":"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h4 id=\"given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\" class=\"color-pink\">Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ?<\/h4>\n<\/div>\n<\/div>\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"algorithm\" class=\"color-green\">Algorithm:<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li>In this method, we store all elements of second array in a hash table (unordered_set). One by one check all elements of first array and print all those elements which are not present in the hash table.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p><b>Example:<\/b><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-cpp code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-cpp code-embed-code\">#include&lt;stdio.h&gt;<br\/> <br\/>\/\/ C++ efficient program to <br\/>\/\/ find elements which are not<br\/>\/\/ present in second array<br\/>#include&lt;bits\/stdc++.h&gt;<br\/>using namespace std;<br\/> <br\/>\/\/ Function for finding elements which are there in a[] but not in b[].<br\/>void findMissing(int a[], int b[], <br\/>                 int n, int m)<br\/>{<br\/>    \/\/ Store all elements of <br\/>    \/\/ second array in a hash table<br\/>    unordered_set  s;<br\/>    for (int i = 0; i &lt; m; i++)<br\/>        s.insert(b[i]);<br\/> <br\/>    \/\/ Print all elements of first array that are not present in hash table<br\/>    for (int i = 0; i &lt; n; i++)<br\/>        if (s.find(a[i]) == s.end())<br\/>            cout &lt;&lt; a[i] &lt;&lt; &quot; &quot;;<br\/>}<br\/> <br\/>\/\/ Driver code<br\/>int main()<br\/>{<br\/>    int a[] = { 1, 2, 6, 3, 4, 5 };<br\/>    int b[] = { 2, 4, 3, 1, 0 };<br\/>    int n = sizeof(a) \/ sizeof(a[0]);<br\/>    int m = sizeof(b) \/ sizeof(b[1]);<br\/>    findMissing(a, b, n, m);<br\/>    return 0;<br\/>} <\/code><\/pre> <\/div>\n<p><b>Output:<\/b><\/p>\n<div class=\"Output\">\n<div class=\"hddn\">\n<figure class=\"highlight\">\n<pre><code class=\"hljs\" data-lang=\"\"><span class=\"nt\">5 6<\/span><\/code><\/pre>\n<\/figure>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : In this method, we store all elements of second array in a hash table&#8230;.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[2080],"tags":[195,491,360,368,211,2178,2175,2176,199,198,363,205,2117,220,2162,2166,2165,2170,2169,2167,2172,2163,2168,2174,2180,2181,222,2164,2122,2182,2177,212,2120,2121,710,2179,207,366,204,217,2116,2171,2173,2123,210,200,2118,968,216,2119,1121],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-accenture-interview-questions-and-answers","tag-applied-materials-interview-questions-and-answers","tag-atos-interview-questions-and-answers","tag-bmc-software-interview-questions-and-answers","tag-bosch-india-software-interview-questions-and-answers","tag-c-program-to-find-missing-number-in-array","tag-c-program-to-identify-missing-numbers-in-a-given-array","tag-c-program-to-identify-the-missing-number-in-an-integer-array","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-ciena-corporation-interview-questions-and-answers","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-einfochips-interview-questions-and-answers","tag-electronics-arts-inc-interview-questions-and-answers","tag-find-all-pairs-in-array","tag-find-k-missing-numbers-in-an-array","tag-find-missing-and-duplicate-number-in-array","tag-find-missing-number-in-a-sequence","tag-find-missing-number-in-array","tag-find-missing-number-in-array-c","tag-find-missing-number-in-array-of-numbers-1-1000","tag-find-missing-number-in-array-of-size-n-containing-numbers-from-1-to-n-only","tag-find-missing-number-in-sorted-array","tag-find-the-missing-number","tag-find-the-missing-number-in-a-sorted-array-of-limited-range","tag-find-the-repeating-and-the-missing","tag-flipkart-interview-questions-and-answers","tag-for-each-element-in-1st-array-count-elements-less-than-or-equal-to-it-in-2nd-array","tag-harman-international-interview-questions-and-answers","tag-how-to-find-missing-number-on-integer-array-of-1-to-100","tag-how-to-find-missing-numbers-in-arrays-in-c-language","tag-indecomm-global-services-interview-questions-and-answers","tag-larsen-toubro-interview-questions-and-answers","tag-mathworks-india-private-limited-interview-questions-and-answers","tag-mavenir-interview-questions-and-answers","tag-missing-number-in-array","tag-mphasis-interview-questions-and-answers","tag-netapp-interview-questions-and-answers","tag-oracle-corporation-interview-questions-and-answers","tag-peoplestrong-interview-questions-and-answers","tag-philips-software-centre-pvt-ltd-interview-questions-and-answers","tag-program-to-find-missing-number-in-an-array","tag-repeat-and-missing-number-array","tag-srm-technologies-interview-questions-and-answers","tag-symphony-teleca-interview-questions-and-answers","tag-tech-mahindra-interview-questions-and-answers","tag-tecnotree-interview-questions-and-answers","tag-wipro-infotech-interview-questions-and-answers","tag-wipro-interview-questions-and-answers","tag-yash-technologies-interview-questions-and-answers","tag-zs-associates-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Wikitechy<\/title>\n<meta name=\"description\" content=\"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Subtract all the numbers from sum and you will get the missing number\" \/>\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.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Wikitechy\" \/>\n<meta property=\"og:description\" content=\"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Subtract all the numbers from sum and you will get the missing number\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-12T21:58:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-24T06:32:47+00:00\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/\",\"name\":\"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Wikitechy\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"datePublished\":\"2021-07-12T21:58:14+00:00\",\"dateModified\":\"2021-08-24T06:32:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Subtract all the numbers from sum and you will get the missing number\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Wikitechy","description":"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Subtract all the numbers from sum and you will get the missing number","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.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/","og_locale":"en_US","og_type":"article","og_title":"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Wikitechy","og_description":"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Subtract all the numbers from sum and you will get the missing number","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/","og_site_name":"Wikitechy","article_published_time":"2021-07-12T21:58:14+00:00","article_modified_time":"2021-08-24T06:32:47+00:00","author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/","name":"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Wikitechy","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"datePublished":"2021-07-12T21:58:14+00:00","dateModified":"2021-08-24T06:32:47+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ? - Subtract all the numbers from sum and you will get the missing number","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/cpp\/given-a-list-of-numbers-fixed-list-now-given-any-other-list-how-can-you-efficiently-find-out-if-there-is-any-element-in-the-second-list-that-is-an-element-of-the-first-list-fixed-list\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=356"}],"version-history":[{"count":2,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":3633,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/356\/revisions\/3633"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}