{"id":35016,"date":"2024-11-01T09:34:38","date_gmt":"2024-11-01T09:34:38","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=35016"},"modified":"2024-11-01T12:51:41","modified_gmt":"2024-11-01T12:51:41","slug":"%ec%bd%94%ed%8b%80%eb%a6%b0-%ec%bd%94%eb%94%a9%ed%85%8c%ec%8a%a4%ed%8a%b8-%ea%b0%95%ec%a2%8c-i-will-become-the-president-of-the-residents-association","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/35016\/","title":{"rendered":"Kotlin Coding Test, I Will Become the President of the Residents&#8217; Association"},"content":{"rendered":"<div class=\"post\">\n<p>\n        Coding tests are an important tool that many companies use to evaluate candidates.<br \/>\n        In particular, algorithm problems are effective in measuring coding skills and problem-solving abilities.<br \/>\n        In this course, we will address the algorithm problem titled &#8220;I will become the head of the residents&#8217; association.&#8221;<br \/>\n        Through this problem, you will be able to develop your understanding of Kotlin\u2019s basic syntax and algorithmic thinking.<br \/>\n        I will explain in detail the essence of the problem, the approach, the code implementation, and optimization methods.\n    <\/p>\n<h2>Problem Description<\/h2>\n<p>\n        One day, a person who wants to become the head of the residents&#8217; association lives in an apartment.<br \/>\n        The structure of this apartment is as follows:\n    <\/p>\n<ul>\n<li>Ground Floor: There is 1 person living in each unit from 1 to n.<\/li>\n<li>1st Floor: The number of people in unit 1 is obtained by adding the number of people on the ground floor, and &#8230;<\/li>\n<li>k-th Floor: The number of residents in unit n is the sum of the number of people from the ground up to the k-th floor.<\/li>\n<\/ul>\n<p>\n        The problem is to calculate the number of residents in a given unit based on the floor and unit number.\n    <\/p>\n<h3>Input Format<\/h3>\n<ul>\n<li>First line: The number of test cases T (1 \u2264 T \u2264 10)<\/li>\n<li>For each test case, two integers K (0 \u2264 K \u2264 14) and N (1 \u2264 N \u2264 14) are given.<\/li>\n<\/ul>\n<h3>Output Format<\/h3>\n<p>For each test case, print the number of residents in the corresponding unit.<\/p>\n<h2>Problem Approach<\/h2>\n<p>\n        This problem can be solved using Dynamic Programming.<br \/>\n        You can approach it in the following way:\n    <\/p>\n<ol>\n<li>\n            Understand the characteristics of the apartment structure and remember that each unit on the ground floor has 1 resident.<br \/>\n            Then, the number of people on the 1st floor is determined by repeatedly adding the number of people on the ground floor.\n        <\/li>\n<li>\n            The number of residents in unit N on the K-th floor is the sum of the residents in unit 1 + unit 2 + &#8230; + unit N on the (K-1)-th floor.<br \/>\n            This has a recursive nature, so it can be solved through recursive calls.\n        <\/li>\n<li>\n            When implementing, create a 2D array to store the number of residents for specific floors and units to facilitate memoization.\n        <\/li>\n<\/ol>\n<h2>Code Implementation<\/h2>\n<p>\n        Below is the code implementing the above algorithm in Kotlin.\n    <\/p>\n<pre><code>\n        fun main() {\n            val t = readLine()!!.toInt()\n            val results = IntArray(t)\n\n            for (i in 0 until t) {\n                val (k, n) = readLine()!!.split(' ').map { it.toInt() }\n                results[i] = calculateResidents(k, n)\n            }\n\n            for (result in results) {\n                println(result)\n            }\n        }\n\n        fun calculateResidents(k: Int, n: Int): Int {\n            \/\/ Initialize structure for 14 floors and 14 units\n            val dp = Array(15) { IntArray(15) }\n\n            \/\/ 1 resident for each unit on the ground floor\n            for (j in 1..14) {\n                dp[0][j] = 1\n            }\n\n            \/\/ Iterate over each floor and each unit\n            for (i in 1..k) {\n                for (j in 1..n) {\n                    \/\/ Add the number of people in unit j on the (i-1)th floor\n                    for (m in 1..j) {\n                        dp[i][j] += dp[i - 1][m]\n                    }\n                }\n            }\n\n            return dp[k][n] \/\/ Return the number of residents in unit n on the k-th floor\n        }\n    <\/code><\/pre>\n<h2>Code Explanation<\/h2>\n<p>\n        In the above code, the `calculateResidents` function calculates the number of residents in the given K-th floor N-th unit.<br \/>\n        This function proceeds through the following steps:\n    <\/p>\n<ol>\n<li>Create a 2D array `dp` and initialize a 15&#215;15 structure.<\/li>\n<li>Set that there is 1 resident in each unit on the ground floor.<\/li>\n<li>For the K-th floor and N-th unit, accumulate the number of people from the (K-1)th floor for all units.<\/li>\n<li>Finally, return the number of residents in unit N on the K-th floor from the DP table.<\/li>\n<\/ol>\n<h2>Time Complexity Analysis<\/h2>\n<p>\n        The time complexity of this problem is O(K * N^2). Since K is at most 14,<br \/>\n        the overall time complexity can be treated as a constant. Therefore, we can solve the problem quickly and efficiently.<br \/>\n        It is important to optimize the code and save memory while implementing it.\n    <\/p>\n<h2>Conclusion<\/h2>\n<p>\n        The &#8220;I will become the head of the residents&#8217; association&#8221; problem is a typical algorithm problem that can be solved through dynamic programming.<br \/>\n        By utilizing Kotlin&#8217;s syntax and solving the problem through DP, you can develop your algorithmic thinking.<br \/>\n        Solving such problems can enhance your competitiveness in coding tests.<br \/>\n        I hope the content learned through this course will be helpful in your actual coding test preparation!\n    <\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Coding tests are an important tool that many companies use to evaluate candidates. In particular, algorithm problems are effective in measuring coding skills and problem-solving abilities. In this course, we will address the algorithm problem titled &#8220;I will become the head of the residents&#8217; association.&#8221; Through this problem, you will be able to develop your &hellip; <a href=\"https:\/\/atmokpo.com\/w\/35016\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Kotlin Coding Test, I Will Become the President of the Residents&#8217; Association&#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":[106],"tags":[],"class_list":["post-35016","post","type-post","status-publish","format-standard","hentry","category----en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Kotlin Coding Test, I Will Become the President of the Residents&#039; Association - \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\/35016\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Kotlin Coding Test, I Will Become the President of the Residents&#039; Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Coding tests are an important tool that many companies use to evaluate candidates. In particular, algorithm problems are effective in measuring coding skills and problem-solving abilities. In this course, we will address the algorithm problem titled &#8220;I will become the head of the residents&#8217; association.&#8221; Through this problem, you will be able to develop your &hellip; \ub354 \ubcf4\uae30 &quot;Kotlin Coding Test, I Will Become the President of the Residents&#8217; Association&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/35016\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:34:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T12:51:41+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\/35016\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35016\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Kotlin Coding Test, I Will Become the President of the Residents&#8217; Association\",\"datePublished\":\"2024-11-01T09:34:38+00:00\",\"dateModified\":\"2024-11-01T12:51:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35016\/\"},\"wordCount\":574,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin coding test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/35016\/\",\"url\":\"https:\/\/atmokpo.com\/w\/35016\/\",\"name\":\"Kotlin Coding Test, I Will Become the President of the Residents' Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:34:38+00:00\",\"dateModified\":\"2024-11-01T12:51:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35016\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/35016\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/35016\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Kotlin Coding Test, I Will Become the President of the Residents&#8217; Association\"}]},{\"@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":"Kotlin Coding Test, I Will Become the President of the Residents' Association - \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\/35016\/","og_locale":"ko_KR","og_type":"article","og_title":"Kotlin Coding Test, I Will Become the President of the Residents' Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Coding tests are an important tool that many companies use to evaluate candidates. In particular, algorithm problems are effective in measuring coding skills and problem-solving abilities. In this course, we will address the algorithm problem titled &#8220;I will become the head of the residents&#8217; association.&#8221; Through this problem, you will be able to develop your &hellip; \ub354 \ubcf4\uae30 \"Kotlin Coding Test, I Will Become the President of the Residents&#8217; Association\"","og_url":"https:\/\/atmokpo.com\/w\/35016\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:34:38+00:00","article_modified_time":"2024-11-01T12:51:41+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\/35016\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/35016\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Kotlin Coding Test, I Will Become the President of the Residents&#8217; Association","datePublished":"2024-11-01T09:34:38+00:00","dateModified":"2024-11-01T12:51:41+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/35016\/"},"wordCount":574,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin coding test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/35016\/","url":"https:\/\/atmokpo.com\/w\/35016\/","name":"Kotlin Coding Test, I Will Become the President of the Residents' Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:34:38+00:00","dateModified":"2024-11-01T12:51:41+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/35016\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/35016\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/35016\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Kotlin Coding Test, I Will Become the President of the Residents&#8217; Association"}]},{"@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\/35016","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=35016"}],"version-history":[{"count":2,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35016\/revisions"}],"predecessor-version":[{"id":38107,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35016\/revisions\/38107"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=35016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=35016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=35016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}