{"id":1115,"date":"2023-03-24T14:06:23","date_gmt":"2023-03-24T22:06:23","guid":{"rendered":"http:\/\/www.tech.dimprash.com\/?p=1115"},"modified":"2023-03-24T14:09:12","modified_gmt":"2023-03-24T22:09:12","slug":"infogain-questions","status":"publish","type":"post","link":"http:\/\/www.tech.dimprash.com\/?p=1115","title":{"rendered":"Infogain Questions"},"content":{"rendered":"<p>1) Given some text find all valid email addresses in it.<\/p>\n<pre>$ret = array();\r\n\r\nfunction isValidEmail($word) {\r\n$domain_parts = array();\r\n$domain = \"\";\r\n\r\n$components = explode(\"@\", $word);\r\n\r\nif (count($components) != 2) {\r\nreturn false;\r\n} else {\r\n$domain = $components[1];\r\n$domain_parts = explode(\".\", $domain);\r\nif (count($domain_parts) &lt; 2) {\r\nreturn false;\r\n}\r\n}\r\nreturn true;\r\n}\r\n\r\nfunction findEmailAddresses($input) {\r\n$result = array();\r\nif ((!$input) || empty($input)) {\r\nreturn $result;\r\n}\r\n$words = explode(\" \", $input);\r\nforeach ($words as $word) {\r\nif (isValidEmail($word)) {\r\n$result[] = $word;\r\n}\r\n}\r\nreturn $result;\r\n}\r\n\r\n$str = \"This valid@email.com is just a test abc@ when @pqr is abc@pqr.com.\";\r\n$ret = findEmailAddresses($str);\r\n\r\nvar_dump($ret);<\/pre>\n<p>2) Given some text and an array of keywords, find all the words in the text which are any combination of the keywords. The below is by sorting. But another way is by hashing the keyword.<\/p>\n<pre>&lt;?php\r\n\r\n$ret = array();\r\n\r\nfunction mysort($str) {\r\n$arr = str_split($str);\r\nsort($arr, SORT_STRING);\r\nreturn implode(\"\",$arr);\r\n}\r\n\r\nfunction findCombinations($input, $keywords) {\r\n$result = array();\r\nif ((!$input) || empty($input)) {\r\nreturn count($result);\r\n}\r\nforeach ($keywords as $keyword) {\r\n$sortedKeywords[] = mysort($keyword);\r\n}\r\nvar_dump($sortedKeywords);\r\n$inputArr = explode(\" \", $input);\r\nforeach ($inputArr as $word) {\r\n$sortedInput[] = mysort($word);\r\n}\r\nvar_dump($sortedInput);\r\nforeach ($sortedInput as $sortedWord) {\r\nif (in_array($sortedWord, $sortedKeywords)) {\r\n$result[] = $sortedWord;\r\n}\r\n}\r\nreturn $result;\r\n\r\n}\r\n\r\n$str = \"This valid@email.com the is eht just a test abc@ when @pqr is abc@pqr.com.\";\r\n$keywords = array(\"het\", \"opo\");\r\n$ret = findCombinations($str, $keywords);\r\n\r\nvar_dump($ret);\r\n?&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1) Given some text find all valid email addresses in it. $ret = array(); function isValidEmail($word) { $domain_parts = array(); $domain = &#8220;&#8221;; $components = explode(&#8220;@&#8221;, $word); if (count($components) != 2) { return false; } else { $domain = $components[1]; $domain_parts = explode(&#8220;.&#8221;, $domain); if (count($domain_parts) &lt; 2) { return false; } } return true; &hellip; <a href=\"http:\/\/www.tech.dimprash.com\/?p=1115\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Infogain Questions<\/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":[15],"tags":[],"class_list":["post-1115","post","type-post","status-publish","format-standard","hentry","category-interview-questions"],"_links":{"self":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/1115","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=1115"}],"version-history":[{"count":3,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/1115\/revisions"}],"predecessor-version":[{"id":1118,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/1115\/revisions\/1118"}],"wp:attachment":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1115"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}