{"id":34674,"date":"2024-11-01T09:30:45","date_gmt":"2024-11-01T09:30:45","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34674"},"modified":"2024-11-01T11:27:02","modified_gmt":"2024-11-01T11:27:02","slug":"swift-coding-test-course-i-dont-want-to-be-a-liar","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34674\/","title":{"rendered":"Swift Coding Test Course, I Don&#8217;t Want to Be a Liar"},"content":{"rendered":"<p><body><\/p>\n<article>\n<header>\n<p>This is a course where you can practice solving various problems for effective algorithm problem-solving. The problem we will tackle today is based on the theme &#8216;I Don&#8217;t Want to Be a Liar&#8217;. Through this problem, you will learn statistical thinking, conditional statements, and list processing techniques.<\/p>\n<\/header>\n<section>\n<h2>Problem Description<\/h2>\n<p>\n                Recently, a participant attended a wedding where he was elected as a slacker. However, there were 100 friends at the wedding whom he did not want to invite. These friends are planning to introduce others as their friends by lying.\n            <\/p>\n<p>\n                Each friend can claim, &#8216;I know A and B&#8217;, about specific individuals. Your task is to verify all the lies and determine whether two friends know the same person.\n            <\/p>\n<p>\n                The given input includes the number of friends and the lying information of each friend. Based on the input information, you need to determine which friends are lying.\n            <\/p>\n<\/section>\n<section>\n<h2>Input Example<\/h2>\n<pre>\n                5\n                1 2\n                2 3\n                3 4\n                4 5\n                1 5\n            <\/pre>\n<p>\n                The first line contains the number of friends N, and the following N lines provide the numbers of the friends each friend knows.\n            <\/p>\n<\/section>\n<section>\n<h2>Output Example<\/h2>\n<pre>\n                Yes\n            <\/pre>\n<p>\n                If the two friends know each other, print &#8216;Yes&#8217;; otherwise, print &#8216;No&#8217;.\n            <\/p>\n<\/section>\n<section>\n<h2>Approach to the Problem<\/h2>\n<p>\n                To solve this problem, we can use graph search algorithms. We represent each friend as a vertex and their relationships as edges to form a graph. We can use search methods such as DFS or BFS to check if two friends know each other.\n            <\/p>\n<p>\n                The basic approach is to store friend relationships in a list and conduct a graph search for the given two friends.\n            <\/p>\n<\/section>\n<section>\n<h2>Code Implementation<\/h2>\n<p>\n                Below is the implementation of the code in Swift.\n            <\/p>\n<pre>\n                <code class=\"language-swift\">\n                import Foundation\n\n                func canKnowEachOther(N: Int, friendships: [(Int, Int)], friendA: Int, friendB: Int) -> String {\n                    \/\/ Initialize graph\n                    var graph = Array(repeating: [Int](), count: N + 1)\n\n                    \/\/ Store friendships\n                    for (a, b) in friendships {\n                        graph[a].append(b)\n                        graph[b].append(a)\n                    }\n\n                    \/\/ Initialize BFS\n                    var queue = [friendA]\n                    var visited = Array(repeating: false, count: N + 1)\n                    visited[friendA] = true\n\n                    while !queue.isEmpty {\n                        let current = queue.removeFirst()\n\n                        \/\/ Did we find friend B?\n                        if current == friendB {\n                            return \"Yes\"\n                        }\n\n                        for neighbor in graph[current] {\n                            if !visited[neighbor] {\n                                visited[neighbor] = true\n                                queue.append(neighbor)\n                            }\n                        }\n                    }\n\n                    return \"No\"\n                }\n\n                \/\/ Input example\n                let N = 5\n                let friendships = [(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)]\n                let result = canKnowEachOther(N: N, friendships: friendships, friendA: 1, friendB: 5)\n                print(result) \/\/ \"Yes\"\n                <\/code>\n            <\/pre>\n<\/section>\n<section>\n<h2>Code Explanation<\/h2>\n<p>\n                The above code operates as follows:\n            <\/p>\n<ul>\n<li><strong>Graph Initialization:<\/strong> Initializes the graph in the form of an adjacency list based on the input friendships.<\/li>\n<li><strong>BFS Search:<\/strong> Starts from the given friend A and executes a BFS to check if we reach friend B. Already visited friends are tracked to avoid revisiting.<\/li>\n<li><strong>Return Result:<\/strong> If friend B is found, it returns &#8220;Yes&#8221;; if not found after finishing the search, it returns &#8220;No&#8221;.<\/li>\n<\/ul>\n<\/section>\n<section>\n<h2>Additional Considerations<\/h2>\n<p>\n                The method for solving this problem is quite intuitive as it involves basic DFS\/BFS searching. However, if the scope of the problem increases, we may need to explore more efficient methods. For example, if the number of friends becomes large, applying the Union-Find algorithm instead of DFS may be performance advantageous.\n            <\/p>\n<p>\n                If more complex relationships or random configurations of data are provided, various techniques (e.g., Dynamic Programming options) can be utilized to address them. It is crucial to consider worst-case time and space complexity when selecting the algorithm design.\n            <\/p>\n<\/section>\n<footer>\n<p>This article is part of a course on solving various problems related to the Swift coding test. Through understanding the problem and exploring solutions, we hope to enhance your problem-solving skills.<\/p>\n<\/footer>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a course where you can practice solving various problems for effective algorithm problem-solving. The problem we will tackle today is based on the theme &#8216;I Don&#8217;t Want to Be a Liar&#8217;. Through this problem, you will learn statistical thinking, conditional statements, and list processing techniques. Problem Description Recently, a participant attended a wedding &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34674\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Swift Coding Test Course, I Don&#8217;t Want to Be a Liar&#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-34674","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, I Don&#039;t Want to Be a Liar - \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\/34674\/\" \/>\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, I Don&#039;t Want to Be a Liar - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"This is a course where you can practice solving various problems for effective algorithm problem-solving. The problem we will tackle today is based on the theme &#8216;I Don&#8217;t Want to Be a Liar&#8217;. Through this problem, you will learn statistical thinking, conditional statements, and list processing techniques. Problem Description Recently, a participant attended a wedding &hellip; \ub354 \ubcf4\uae30 &quot;Swift Coding Test Course, I Don&#8217;t Want to Be a Liar&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34674\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:30:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:27:02+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\/34674\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34674\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Swift Coding Test Course, I Don&#8217;t Want to Be a Liar\",\"datePublished\":\"2024-11-01T09:30:45+00:00\",\"dateModified\":\"2024-11-01T11:27:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34674\/\"},\"wordCount\":473,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Swift Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34674\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34674\/\",\"name\":\"Swift Coding Test Course, I Don't Want to Be a Liar - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:30:45+00:00\",\"dateModified\":\"2024-11-01T11:27:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34674\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34674\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34674\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swift Coding Test Course, I Don&#8217;t Want to Be a Liar\"}]},{\"@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, I Don't Want to Be a Liar - \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\/34674\/","og_locale":"ko_KR","og_type":"article","og_title":"Swift Coding Test Course, I Don't Want to Be a Liar - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"This is a course where you can practice solving various problems for effective algorithm problem-solving. The problem we will tackle today is based on the theme &#8216;I Don&#8217;t Want to Be a Liar&#8217;. Through this problem, you will learn statistical thinking, conditional statements, and list processing techniques. Problem Description Recently, a participant attended a wedding &hellip; \ub354 \ubcf4\uae30 \"Swift Coding Test Course, I Don&#8217;t Want to Be a Liar\"","og_url":"https:\/\/atmokpo.com\/w\/34674\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:30:45+00:00","article_modified_time":"2024-11-01T11:27:02+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\/34674\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34674\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Swift Coding Test Course, I Don&#8217;t Want to Be a Liar","datePublished":"2024-11-01T09:30:45+00:00","dateModified":"2024-11-01T11:27:02+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34674\/"},"wordCount":473,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Swift Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34674\/","url":"https:\/\/atmokpo.com\/w\/34674\/","name":"Swift Coding Test Course, I Don't Want to Be a Liar - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:30:45+00:00","dateModified":"2024-11-01T11:27:02+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34674\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34674\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34674\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Swift Coding Test Course, I Don&#8217;t Want to Be a Liar"}]},{"@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\/34674","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=34674"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34674\/revisions"}],"predecessor-version":[{"id":34675,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34674\/revisions\/34675"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}