{"id":213,"date":"2019-01-31T19:35:34","date_gmt":"2019-02-01T00:35:34","guid":{"rendered":"https:\/\/resrvoir.com\/?page_id=213"},"modified":"2025-06-17T22:47:41","modified_gmt":"2025-06-18T02:47:41","slug":"is-an-anagram","status":"publish","type":"page","link":"https:\/\/resrvoir.com\/?page_id=213","title":{"rendered":"Is Anagram (easy)"},"content":{"rendered":"\r\n<p>Write a function that determines if one string is an anagram of another string.<br \/><br \/>An anagram is rearranging letters of words or phrases to create new words or phrases. For example, &#8220;debit card&#8221; and &#8220;bad credit&#8221; are anagrams of each other.<\/p>\r\n\r\n\r\n\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">func isAnagram(s1: String, s2: String) -&gt; Bool {\r\n  var counts = [Character: Int]()\r\n  \r\n  for c in s1 {\r\n    let count = counts[c] ?? 0\r\n    counts[c] = count + 1\r\n  }\r\n  \r\n  for c in s2 {\r\n    let count = counts[c] ?? 0\r\n    \r\n    if count &lt;= 0 {\r\n      return false\r\n    }\r\n    \r\n    counts[c] = count - 1\r\n  }\r\n  \r\n  for (_, count) in counts {\r\n    if count != 0 {\r\n      return false\r\n    }\r\n  }\r\n  \r\n  return true\r\n}\r\n\r\nisAnagram(s1:\"elvis\", s2:\"lives\")\r\nisAnagram(s1:\"eleven plus two\", s2:\"twelve plus one\")\r\nisAnagram(s1:\"debit card\", s2:\"bad credit\")\r\nisAnagram(s1:\"abc\", s2:\"123\")\r\nisAnagram(s1:\"cinema\", s2:\"iceman\")\r\n<\/pre>\r\n","protected":false},"excerpt":{"rendered":"<p>Write a function that determines if one string is an anagram of another string. An anagram is rearranging letters of words or phrases to create new words or phrases. For example, &#8220;debit card&#8221; and &#8220;bad credit&#8221; are anagrams of each other.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":13,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/resrvoir.com\/index.php?rest_route=\/wp\/v2\/pages\/213"}],"collection":[{"href":"https:\/\/resrvoir.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/resrvoir.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/resrvoir.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/resrvoir.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213"}],"version-history":[{"count":13,"href":"https:\/\/resrvoir.com\/index.php?rest_route=\/wp\/v2\/pages\/213\/revisions"}],"predecessor-version":[{"id":1412,"href":"https:\/\/resrvoir.com\/index.php?rest_route=\/wp\/v2\/pages\/213\/revisions\/1412"}],"up":[{"embeddable":true,"href":"https:\/\/resrvoir.com\/index.php?rest_route=\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/resrvoir.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}