{"id":135930,"date":"2022-09-12T03:47:10","date_gmt":"2022-09-12T03:47:10","guid":{"rendered":"https:\/\/www.sushilkumar.ind.in\/blog\/?p=135930"},"modified":"2022-09-12T04:46:11","modified_gmt":"2022-09-12T04:46:11","slug":"given-an-array-of-integers-a-your-task-is-to-count-the-number-of-pairs-i-and-j-where-0-%e2%89%a4-i-j-a-length-such-that-ai-and-aj-are-digit-anagrams","status":"publish","type":"post","link":"https:\/\/www.sushilkumar.ind.in\/blog\/javascript\/given-an-array-of-integers-a-your-task-is-to-count-the-number-of-pairs-i-and-j-where-0-%e2%89%a4-i-j-a-length-such-that-ai-and-aj-are-digit-anagrams\/","title":{"rendered":"Given an array of integers a, your task is to count the number of pairs i and j (where 0 \u2264 i < j < a.length), such that a[i] and a[j] are digit anagrams."},"content":{"rendered":"\n<p>Given an array of integers a, your task is to count the number of pairs i and j (where 0 \u2264 i &lt; j &lt; a.length), such that a[i] and a[j] are digit anagrams.<\/p>\n\n\n\n<p>Two integers are considered to be digit anagrams if they contain the same digits. In other words, one can be obtained from the other by rearranging the digits (or trivially, if the numbers are equal). For example, 54275 and 45572 are digit anagrams, but 321 and 782 are not (since they don&#8217;t contain the same digits). 220 and 22 are also not considered as digit anagrams, since they don&#8217;t even have the same number of digits.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>For a = [25, 35, 872, 228, 53, 278, 872], the output should be solution(a) = 4.<\/p>\n\n\n\n<p>There are 4 pairs of digit anagrams:<\/p>\n\n\n\n<p>a[1] = 35 and a[4] = 53 (i = 1 and j = 4),<\/p>\n\n\n\n<p>a[2] = 872 and a[5] = 278 (i = 2 and j = 5),<\/p>\n\n\n\n<p>a[2] = 872 and a[6] = 872 (i = 2 and j = 6),<\/p>\n\n\n\n<p>a[5] = 278 and a[6] = 872 (i = 5 and j = 6).<\/p>\n\n\n\n<p>Input\/Output<\/p>\n\n\n\n[execution time limit] 4 seconds (js)<\/p>\n\n\n\n[input] array.integer a<\/p>\n\n\n\n<p>An array of non-negative integers.<\/p>\n\n\n\n<p>Guaranteed constraints:<\/p>\n\n\n\n<p>1 \u2264 a.length \u2264 105,<\/p>\n\n\n\n<p>0 \u2264 a[i] \u2264 109.<\/p>\n\n\n\n[output] integer64<\/p>\n\n\n\n<p>The number of pairs i and j, such that a[i] and a[j] are digit anagrams.<\/p>\n\n\n\n[JavaScript] Syntax Tips<\/p>\n\n\n\n<p>\/\/ Prints help message to the console<\/p>\n\n\n\n<p>\/\/ Returns a string<\/p>\n\n\n\n<p>function helloWorld(name) {<\/p>\n\n\n\n<p>&nbsp; &nbsp; console.log(&#8220;This prints to the console when you Run Tests&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; return &#8220;Hello, &#8221; + name;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Solution: <\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\n    function mergeStringsSolution( s1, s2)\n    {\n        \/\/ Stores length of string s1\n        var leng1 = s1.length;\n    \n        \/\/ Stores length of string s2\n        var leng2 = s2.length;\n    \n        \/\/ Pointer to beginning\n        \/\/ of string1 i.e., s1\n        var out1 = 0;\n    \n        \/\/ Pointer to beginning\n        \/\/ of string2 i.e., s2\n        var out2 = 0;\n    \n        \/\/ Stores the final string\n        var result = \"\";\n    \n        \/\/ Traverse the strings\n        while (out1 &lt; leng1 &amp;&amp; out2 &lt; leng2) {\n    \n            \/\/ Append the smaller of the\n            \/\/ two current characters\n            if (s1&#91;out1] &lt; s2&#91;out2]) {\n                result += s1&#91;out1];\n                out1++;\n            }\n    \n            else {\n                result += s2&#91;out2];\n                out2++;\n            }\n        }\n    \n        \/\/ Append the remaining characters\n        \/\/ of any of the two strings\n        if (out1 &lt; leng1) {\n            result += s1.substr(out1, leng1);\n        }\n        if (out2 &lt; leng2) {\n            result += s2.substr(out2, leng2);\n        }\n    \n        \/\/ Print the final string\n        console.log(result);\n    }\n    \n    \/\/ Driver Code\n    var S1 = \"super\";\n    var S2 = \"tower\";\n    \/\/ Function Call\n    mergeStringsSolution(S1, S2);\n    \n    \/\/ output is : stouperwer\n    <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given an array of integers a, your task is to count the number of pairs i and j (where 0 \u2264 i &lt; j &lt; a.length), such that a[i] and a[j] are digit anagrams. Two integers are considered to be digit anagrams if they contain the same digits. In other words, one can be obtained &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[323],"tags":[],"class_list":["post-135930","post","type-post","status-publish","format-standard","","category-javascript"],"jetpack_publicize_connections":[],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p99pkJ-zmq","_links":{"self":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/135930"}],"collection":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/comments?post=135930"}],"version-history":[{"count":0,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/135930\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/media?parent=135930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/categories?post=135930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/tags?post=135930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}