{"id":35022,"date":"2024-11-01T09:34:44","date_gmt":"2024-11-01T09:34:44","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=35022"},"modified":"2024-11-01T11:45:17","modified_gmt":"2024-11-01T11:45:17","slug":"%d0%baotlin-coding-test-course-finding-building-order","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/35022\/","title":{"rendered":"\u041aotlin Coding Test Course, Finding Building Order"},"content":{"rendered":"<p><body><\/p>\n<p>In coding tests, algorithm problems usually involve designing an algorithm to solve a specific problem. In this course, we will tackle the problem titled &#8216;Finding the Order of Buildings&#8217; using Kotlin.<\/p>\n<h2>Problem Description<\/h2>\n<p>Given input consists of the height and position of multiple buildings. We need to determine the order in which each building is visible, considering all the given buildings. In other words, we aim to find out how the order is determined when one building is behind another, making it not visible.<\/p>\n<h3>Input Format<\/h3>\n<pre><code>\n    The first line contains the number of buildings N (1 \u2264 N \u2264 200,000).\n    Then, for N lines, each building's height H (1 \u2264 H \u2264 10^9) and position P (1 \u2264 P \u2264 10^9) are given.\n    <\/code><\/pre>\n<h3>Output Format<\/h3>\n<pre><code>\n    Output N integers representing the order in which each building is visible.\n    <\/code><\/pre>\n<h2>Problem Solving Approach<\/h2>\n<p>To solve this problem, we must analyze the relationship between each building&#8217;s height and position relative to other buildings. We follow these steps:<\/p>\n<ol>\n<li>Sort the provided buildings based on <strong>height<\/strong> and <strong>position<\/strong>.<\/li>\n<li>Check each sorted building one by one to determine if it is visible.<\/li>\n<li>Then, count the number of visible buildings to collect the results.<\/li>\n<\/ol>\n<h2>Code Implementation<\/h2>\n<p>Now, let&#8217;s implement the code in Kotlin to solve the problem based on the discussed approach:<\/p>\n<pre><code>\n    data class Building(val height: Int, val position: Int)\n\n    fun findVisibleBuildings(buildings: List<Building>): List<Int> {\n        \/\/ Sort buildings (sorting by height in descending order)\n        val sortedBuildings = buildings.sortedWith(compareByDescending<Building> { it.height }.thenBy { it.position })\n        val visibleCount = mutableListOf<Int>()\n        \n        var lastHeight = 0\n        \n        for (building in sortedBuildings) {\n            if (building.height > lastHeight) {\n                visibleCount.add(building.position)\n                lastHeight = building.height\n            }\n        }\n        \n        \/\/ Sort to return results in original order\n        return visibleCount.sorted()\n    }\n\n    fun main() {\n        val buildingCount = readLine()!!.toInt()\n        val buildings = mutableListOf<Building>()\n        \n        for (i in 0 until buildingCount) {\n            val (height, position) = readLine()!!.split(\" \").map { it.toInt() }\n            buildings.add(Building(height, position))\n        }\n        \n        val result = findVisibleBuildings(buildings)\n        println(result.joinToString(\" \"))\n    }\n    <\/code><\/pre>\n<h2>Code Explanation<\/h2>\n<p>The code above provides comments to explain the flow, but to summarize, it consists of the following steps:<\/p>\n<ol>\n<li>Create a <code>Building<\/code> data class to hold the building information.<\/li>\n<li>Sort the given buildings in descending order of height.<\/li>\n<li>If the current building&#8217;s height is greater than the tallest building checked so far, add its position to <code>visibleCount<\/code>.<\/li>\n<li>After checking all buildings, return the results sorted in their original order.<\/li>\n<\/ol>\n<h2>Time Complexity Analysis<\/h2>\n<p>The time complexity of this algorithm is O(N log N). This is the sum of the time taken to sort the list of buildings and the time taken to find the tallest building. Therefore, it can efficiently handle large datasets.<\/p>\n<h2>Conclusion<\/h2>\n<p>Through this course, we learned how to solve the &#8216;Finding the Order of Buildings&#8217; problem using Kotlin. There are various approaches to solving algorithm problems, and understanding and verifying them is crucial. I hope to further enhance coding skills through various problems in the future.<\/p>\n<h2>Future References<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.example.com\/algorithm-1\">Basic Concepts of Algorithms<\/a><\/li>\n<li><a href=\"https:\/\/www.example.com\/kotlin-introduction\">Introduction to Kotlin<\/a><\/li>\n<li><a href=\"https:\/\/www.example.com\/data-structure\">Data Structures and Algorithms<\/a><\/li>\n<\/ul>\n<p>Thank you!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In coding tests, algorithm problems usually involve designing an algorithm to solve a specific problem. In this course, we will tackle the problem titled &#8216;Finding the Order of Buildings&#8217; using Kotlin. Problem Description Given input consists of the height and position of multiple buildings. We need to determine the order in which each building is &hellip; <a href=\"https:\/\/atmokpo.com\/w\/35022\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;\u041aotlin Coding Test Course, Finding Building Order&#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-35022","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>\u041aotlin Coding Test Course, Finding Building Order - \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\/35022\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u041aotlin Coding Test Course, Finding Building Order - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In coding tests, algorithm problems usually involve designing an algorithm to solve a specific problem. In this course, we will tackle the problem titled &#8216;Finding the Order of Buildings&#8217; using Kotlin. Problem Description Given input consists of the height and position of multiple buildings. We need to determine the order in which each building is &hellip; \ub354 \ubcf4\uae30 &quot;\u041aotlin Coding Test Course, Finding Building Order&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/35022\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:34:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:45:17+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=\"2\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/35022\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35022\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"\u041aotlin Coding Test Course, Finding Building Order\",\"datePublished\":\"2024-11-01T09:34:44+00:00\",\"dateModified\":\"2024-11-01T11:45:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35022\/\"},\"wordCount\":348,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin coding test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/35022\/\",\"url\":\"https:\/\/atmokpo.com\/w\/35022\/\",\"name\":\"\u041aotlin Coding Test Course, Finding Building Order - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:34:44+00:00\",\"dateModified\":\"2024-11-01T11:45:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35022\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/35022\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/35022\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u041aotlin Coding Test Course, Finding Building Order\"}]},{\"@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":"\u041aotlin Coding Test Course, Finding Building Order - \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\/35022\/","og_locale":"ko_KR","og_type":"article","og_title":"\u041aotlin Coding Test Course, Finding Building Order - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In coding tests, algorithm problems usually involve designing an algorithm to solve a specific problem. In this course, we will tackle the problem titled &#8216;Finding the Order of Buildings&#8217; using Kotlin. Problem Description Given input consists of the height and position of multiple buildings. We need to determine the order in which each building is &hellip; \ub354 \ubcf4\uae30 \"\u041aotlin Coding Test Course, Finding Building Order\"","og_url":"https:\/\/atmokpo.com\/w\/35022\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:34:44+00:00","article_modified_time":"2024-11-01T11:45:17+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":"2\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/35022\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/35022\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"\u041aotlin Coding Test Course, Finding Building Order","datePublished":"2024-11-01T09:34:44+00:00","dateModified":"2024-11-01T11:45:17+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/35022\/"},"wordCount":348,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin coding test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/35022\/","url":"https:\/\/atmokpo.com\/w\/35022\/","name":"\u041aotlin Coding Test Course, Finding Building Order - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:34:44+00:00","dateModified":"2024-11-01T11:45:17+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/35022\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/35022\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/35022\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"\u041aotlin Coding Test Course, Finding Building Order"}]},{"@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\/35022","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=35022"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35022\/revisions"}],"predecessor-version":[{"id":35023,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35022\/revisions\/35023"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=35022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=35022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=35022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}