{"id":959,"date":"2017-04-30T15:41:11","date_gmt":"2017-04-30T23:41:11","guid":{"rendered":"http:\/\/www.tech.dimprash.com\/?p=959"},"modified":"2019-09-03T16:38:05","modified_gmt":"2019-09-04T00:38:05","slug":"combinations-of-a-string","status":"publish","type":"post","link":"http:\/\/www.tech.dimprash.com\/?p=959","title":{"rendered":"Combinations of a String"},"content":{"rendered":"<p>Implement a function that prints all possible combinations of a string.<\/p>\n<p>A string &#8220;12&#8221; is the same as string &#8220;21&#8221;.<\/p>\n<p>Note : The below function will work for unique strings like &#8220;wxyz&#8221; but not for &#8220;aabc&#8221;.\u00a0 One quick to fix it for &#8220;aabc&#8221; would be to store the output strings in a hash and then output the hash.<\/p>\n<p>Check this video for good explanation of &#8220;AABC&#8221; :<\/p>\n<p><iframe loading=\"lazy\" title=\"Combination of Characters in String (All subsets of characters)\" width=\"660\" height=\"371\" src=\"https:\/\/www.youtube.com\/embed\/xTNFs5KRV_g?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<pre>function combine($instr, $outstr, $index)\r\n{\r\n    for ($i = $index; $i &lt; strlen($instr); $i++)\r\n    {\r\n\r\n        $outstr = $outstr . $instr[$i];\r\n        echo \"$outstr\\n\";\r\n        combine($instr, $outstr, $i + 1);\r\n        $outstr = substr($outstr, 0, -1);\r\n    }\r\n}\r\n\r\ncombine(\"wxyz\", \"\", 0);\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Implement a function that prints all possible combinations of a string. A string &#8220;12&#8221; is the same as string &#8220;21&#8221;. Note : The below function will work for unique strings like &#8220;wxyz&#8221; but not for &#8220;aabc&#8221;.\u00a0 One quick to fix it for &#8220;aabc&#8221; would be to store the output strings in a hash and then &hellip; <a href=\"http:\/\/www.tech.dimprash.com\/?p=959\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Combinations of a String<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-959","post","type-post","status-publish","format-standard","hentry","category-algorithms"],"_links":{"self":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=959"}],"version-history":[{"count":3,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/959\/revisions"}],"predecessor-version":[{"id":1063,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/959\/revisions\/1063"}],"wp:attachment":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=959"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}