{"id":34826,"date":"2024-11-01T09:32:26","date_gmt":"2024-11-01T09:32:26","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34826"},"modified":"2024-11-01T11:26:22","modified_gmt":"2024-11-01T11:26:22","slug":"swift-coding-test-course-find-the-number-of-colloquial-expressions","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34826\/","title":{"rendered":"Swift Coding Test Course, Find the Number of Colloquial Expressions"},"content":{"rendered":"<p><body><\/p>\n<header>\n<p>Author: [Author Name]<\/p>\n<p>Date: [Date]<\/p>\n<\/header>\n<section>\n<h2>1. What is a Binary Friend Number?<\/h2>\n<p>A Binary Friend Number refers to a binary string that satisfies the following conditions:<\/p>\n<ul>\n<li>It is composed only of 0s and 1s.<\/li>\n<li>There cannot be consecutive digits &#8216;1&#8217;. In other words, the substring &#8217;11&#8217; must not exist.<\/li>\n<li>The string must start and end with 0.<\/li>\n<\/ul>\n<p>For example, &#8216;010&#8217;, &#8216;0010&#8217;, and &#8216;1000&#8217; are Binary Friend Numbers. In contrast, &#8217;11&#8217;, &#8216;110&#8217;, &#8216;0110&#8217;, and &#8216;0001&#8217; are not Binary Friend Numbers.<\/p>\n<h2>2. Problem Definition of Binary Friend Numbers<\/h2>\n<p>Given a natural number n, we define the problem of finding the count of Binary Friend Numbers of length n. This problem can be efficiently solved using Dynamic Programming.<\/p>\n<h2>3. Problem Examples<\/h2>\n<p>For example, the Binary Friend Numbers of length 1 are &#8216;0&#8217; and &#8216;1&#8217;, totaling 2. However, the Binary Friend Numbers of length 2 are &#8217;00&#8217;, &#8217;01&#8217;, and &#8217;10&#8217;, totaling 3. The Binary Friend Numbers of length 3 are &#8216;000&#8217;, &#8216;001&#8217;, &#8216;010&#8217;, &#8216;100&#8217;, and &#8216;101&#8217;, totaling 5, while for length 4, they are &#8216;0000&#8217;, &#8216;0001&#8217;, &#8216;0010&#8217;, &#8216;0100&#8217;, &#8216;0101&#8217;, &#8216;1000&#8217;, &#8216;1001&#8217;, and &#8216;1010&#8217;, totaling 8. One can find patterns in this manner.<\/p>\n<h2>4. Approach to the Problem<\/h2>\n<p>This problem has the following recursive properties:<\/p>\n<ul>\n<li>A Binary Friend Number of length n can be derived from Binary Friend Numbers of length n-1 and has two cases: one that ends with 0 and one that ends with 1.<\/li>\n<li>Thus, it can be expressed as dp[n] = dp[n-1] + dp[n-2].<\/li>\n<\/ul>\n<h2>5. Implementation Using Dynamic Programming<\/h2>\n<p>Now, based on the above relationship, let&#8217;s write a code to compute Binary Friend Numbers in Swift. Below is an example of Swift code:<\/p>\n<pre>\n            <code>\n                func countBinaryFriends(n: Int) -> Int {\n                    guard n > 1 else { return n }\n                    \n                    var dp = [Int](repeating: 0, count: n + 1)\n                    dp[1] = 2 \/\/ 0, 1\n                    dp[2] = 3 \/\/ 00, 01, 10\n                    \n                    for i in 3...n {\n                        dp[i] = dp[i - 1] + dp[i - 2]\n                    }\n                    \n                    return dp[n]\n                }\n\n                let n = 4 \/\/ Example input\n                print(countBinaryFriends(n: n)) \/\/ Output the count of Binary Friend Numbers\n            <\/code>\n        <\/pre>\n<h2>6. Time Complexity and Space Complexity<\/h2>\n<p>The above algorithm has a time complexity of O(n) concerning n. Additionally, since it utilizes a dp array, it has a space complexity of O(n). If optimized, the space complexity can be reduced to O(1) by only remembering the two previous values:<\/p>\n<pre>\n            <code>\n                func optimizedCountBinaryFriends(n: Int) -> Int {\n                    guard n > 1 else { return n }\n                    \n                    var prev1 = 2 \/\/ dp[1]\n                    var prev2 = 3 \/\/ dp[2]\n                    var current = 0\n\n                    for i in 3...n {\n                        current = prev1 + prev2\n                        prev1 = prev2\n                        prev2 = current\n                    }\n                    \n                    return current\n                }\n\n                let n = 4 \/\/ Example input\n                print(optimizedCountBinaryFriends(n: n)) \/\/ Output the count of optimized Binary Friend Numbers\n            <\/code>\n        <\/pre>\n<h2>7. Conclusion<\/h2>\n<p>Through the above process, we were able to solve the problem of finding Binary Friend Numbers. This problem serves as a good example for understanding the basics of Dynamic Programming. I hope you understand and remember the patterns that occur during the process of finding Binary Friend Numbers, as this will help in solving similar problems.<\/p>\n<h2>8. Additional Learning Materials<\/h2>\n<p>Additionally, it is important to review and practice problems related to algorithms and data structures. Below are recommended resources:<\/p>\n<ul>\n<li><a href=\"https:\/\/leetcode.com\/\">LeetCode<\/a>: Various algorithm problem solutions<\/li>\n<li><a href=\"https:\/\/www.hackerrank.com\/\">HackerRank<\/a>: Coding test practice<\/li>\n<li><a href=\"https:\/\/www.geeksforgeeks.org\/\">GeeksforGeeks<\/a>: Knowledge sharing on data structures and algorithms<\/li>\n<\/ul>\n<\/section>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Author: [Author Name] Date: [Date] 1. What is a Binary Friend Number? A Binary Friend Number refers to a binary string that satisfies the following conditions: It is composed only of 0s and 1s. There cannot be consecutive digits &#8216;1&#8217;. In other words, the substring &#8217;11&#8217; must not exist. The string must start and end &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34826\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Swift Coding Test Course, Find the Number of Colloquial Expressions&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[129],"tags":[],"class_list":["post-34826","post","type-post","status-publish","format-standard","hentry","category-swift-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Swift Coding Test Course, Find the Number of Colloquial Expressions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/34826\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift Coding Test Course, Find the Number of Colloquial Expressions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Author: [Author Name] Date: [Date] 1. What is a Binary Friend Number? A Binary Friend Number refers to a binary string that satisfies the following conditions: It is composed only of 0s and 1s. There cannot be consecutive digits &#8216;1&#8217;. In other words, the substring &#8217;11&#8217; must not exist. The string must start and end &hellip; \ub354 \ubcf4\uae30 &quot;Swift Coding Test Course, Find the Number of Colloquial Expressions&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34826\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:32:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:26:22+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34826\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34826\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Swift Coding Test Course, Find the Number of Colloquial Expressions\",\"datePublished\":\"2024-11-01T09:32:26+00:00\",\"dateModified\":\"2024-11-01T11:26:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34826\/\"},\"wordCount\":386,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Swift Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34826\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34826\/\",\"name\":\"Swift Coding Test Course, Find the Number of Colloquial Expressions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:32:26+00:00\",\"dateModified\":\"2024-11-01T11:26:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34826\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34826\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34826\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swift Coding Test Course, Find the Number of Colloquial Expressions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Swift Coding Test Course, Find the Number of Colloquial Expressions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","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:\/\/atmokpo.com\/w\/34826\/","og_locale":"ko_KR","og_type":"article","og_title":"Swift Coding Test Course, Find the Number of Colloquial Expressions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Author: [Author Name] Date: [Date] 1. What is a Binary Friend Number? A Binary Friend Number refers to a binary string that satisfies the following conditions: It is composed only of 0s and 1s. There cannot be consecutive digits &#8216;1&#8217;. In other words, the substring &#8217;11&#8217; must not exist. The string must start and end &hellip; \ub354 \ubcf4\uae30 \"Swift Coding Test Course, Find the Number of Colloquial Expressions\"","og_url":"https:\/\/atmokpo.com\/w\/34826\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:32:26+00:00","article_modified_time":"2024-11-01T11:26:22+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34826\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34826\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Swift Coding Test Course, Find the Number of Colloquial Expressions","datePublished":"2024-11-01T09:32:26+00:00","dateModified":"2024-11-01T11:26:22+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34826\/"},"wordCount":386,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Swift Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34826\/","url":"https:\/\/atmokpo.com\/w\/34826\/","name":"Swift Coding Test Course, Find the Number of Colloquial Expressions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:32:26+00:00","dateModified":"2024-11-01T11:26:22+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34826\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34826\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34826\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Swift Coding Test Course, Find the Number of Colloquial Expressions"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=34826"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34826\/revisions"}],"predecessor-version":[{"id":34827,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34826\/revisions\/34827"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}