{"id":35188,"date":"2024-11-01T09:36:32","date_gmt":"2024-11-01T09:36:32","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=35188"},"modified":"2024-11-01T11:44:43","modified_gmt":"2024-11-01T11:44:43","slug":"kotlin-coding-test-course-assign-meeting-rooms","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/35188\/","title":{"rendered":"kotlin coding test course, assign meeting rooms"},"content":{"rendered":"<p><body><\/p>\n<h2>Problem Description<\/h2>\n<p>\n        The meeting room allocation problem is an algorithmic problem that efficiently allocates meeting rooms based on a given list of times.<br \/>\n        There are N meetings, and each meeting has a start time and an end time.<br \/>\n        A meeting room can only hold one meeting at a time, and if there are meetings occurring at the same time, those meetings cannot be allocated.<br \/>\n        Therefore, write an algorithm that maximizes the number of meetings that can be allocated.\n    <\/p>\n<h2>Input Format<\/h2>\n<pre><code>\n    - The first line contains N (1 \u2264 N \u2264 100,000).\n    - The next N lines provide the start and end times of each meeting.\n    - The start time is less than the end time, and all times are integers between 0 and 10^6.\n    <\/code><\/pre>\n<h2>Output Format<\/h2>\n<pre><code>\n    - Output the maximum number of meetings that can be allocated.\n    <\/code><\/pre>\n<h2>Example<\/h2>\n<p><strong>Input Example:<\/strong><\/p>\n<pre><code>\n    5\n    1 3\n    2 4\n    3 5\n    5 6\n    4 7\n    <\/code><\/pre>\n<p><strong>Output Example:<\/strong><\/p>\n<pre><code>\n    4\n    <\/code><\/pre>\n<h2>Problem Solving Process<\/h2>\n<p>\n        This problem can be approached using a greedy algorithm.<br \/>\n        A greedy algorithm is a methodology that makes the optimal choice at each step to find the overall optimal solution.<br \/>\n        In the case of the meeting room allocation problem, sorting meetings by their end times and allocating as many meetings as possible is the most effective method.\n    <\/p>\n<h3>1. Sorting Meetings<\/h3>\n<p>\n        Sorting needs to be done based on the end times of the meetings.<br \/>\n        By prioritizing meetings that end earlier, you can use the start times of later meetings to allocate more meetings.\n    <\/p>\n<p>\n        For example, when the meeting data is as follows:\n    <\/p>\n<pre><code>\n    1 3\n    2 4\n    3 5\n    5 6\n    4 7\n    <\/code><\/pre>\n<p>\n        If we sort this data based on end times, it will look like this:\n    <\/p>\n<pre><code>\n    1 3\n    2 4\n    3 5\n    4 7\n    5 6\n    <\/code><\/pre>\n<h3>2. Calculating Possible Meetings<\/h3>\n<p>\n        Based on the sorted list of meetings, we iterate through each meeting to calculate how many meetings can be allocated.<br \/>\n        We check the next meeting that can start after the fastest ending meeting.\n    <\/p>\n<p>\n        To do this, we use a variable <code>lastEnd<\/code> to record the end time of the last allocated meeting.<br \/>\n        Only those meetings whose start time is greater than or equal to <code>lastEnd<\/code> can be allocated.\n    <\/p>\n<h3>3. Code Implementation<\/h3>\n<p>\n        The following code implements the above logic.<br \/>\n        Let\u2019s write the Kotlin code as follows.\n    <\/p>\n<pre><code>\n    fun maxMeetings(meetings: Array<pair<int, int=\"\">&gt;): Int {\n        \/\/ Sort meetings by end time\n        val sortedMeetings = meetings.sortedBy { it.second }\n        var count = 0\n        var lastEndTime = 0\n\n        for (meeting in sortedMeetings) {\n            \/\/ Allocate meeting if the start time is greater than or equal to the end time of the last meeting\n            if (meeting.first &gt;= lastEndTime) {\n                count++\n                lastEndTime = meeting.second\n            }\n        }\n        return count\n    }\n\n    fun main() {\n        val n = readLine()!!.toInt()\n        val meetings = Array(n) {\n            val input = readLine()!!.split(\" \")\n            Pair(input[0].toInt(), input[1].toInt())\n        }\n        println(maxMeetings(meetings))\n    }\n    <\/pair<int,><\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>\n        In this post, we solved the meeting room allocation problem using Kotlin.<br \/>\n        By using a greedy algorithm, we sorted the meeting data based on their end times and checked the start times of each meeting to allocate as many as possible.<br \/>\n        This problem serves as a good example of how a greedy algorithm can be used to find an optimal solution efficiently.\n    <\/p>\n<p>\n        Applying such logic and approaches to various problems could lead to excellent performance in coding tests.<br \/>\n        Now, we encourage you to take on similar problems!\n    <\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description The meeting room allocation problem is an algorithmic problem that efficiently allocates meeting rooms based on a given list of times. There are N meetings, and each meeting has a start time and an end time. A meeting room can only hold one meeting at a time, and if there are meetings occurring &hellip; <a href=\"https:\/\/atmokpo.com\/w\/35188\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;kotlin coding test course, assign meeting rooms&#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-35188","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 course, assign meeting rooms - \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\/35188\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"kotlin coding test course, assign meeting rooms - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Problem Description The meeting room allocation problem is an algorithmic problem that efficiently allocates meeting rooms based on a given list of times. There are N meetings, and each meeting has a start time and an end time. A meeting room can only hold one meeting at a time, and if there are meetings occurring &hellip; \ub354 \ubcf4\uae30 &quot;kotlin coding test course, assign meeting rooms&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/35188\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:36:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:44:43+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\/35188\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35188\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"kotlin coding test course, assign meeting rooms\",\"datePublished\":\"2024-11-01T09:36:32+00:00\",\"dateModified\":\"2024-11-01T11:44:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35188\/\"},\"wordCount\":383,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin coding test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/35188\/\",\"url\":\"https:\/\/atmokpo.com\/w\/35188\/\",\"name\":\"kotlin coding test course, assign meeting rooms - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:36:32+00:00\",\"dateModified\":\"2024-11-01T11:44:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35188\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/35188\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/35188\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"kotlin coding test course, assign meeting rooms\"}]},{\"@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 course, assign meeting rooms - \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\/35188\/","og_locale":"ko_KR","og_type":"article","og_title":"kotlin coding test course, assign meeting rooms - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Problem Description The meeting room allocation problem is an algorithmic problem that efficiently allocates meeting rooms based on a given list of times. There are N meetings, and each meeting has a start time and an end time. A meeting room can only hold one meeting at a time, and if there are meetings occurring &hellip; \ub354 \ubcf4\uae30 \"kotlin coding test course, assign meeting rooms\"","og_url":"https:\/\/atmokpo.com\/w\/35188\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:36:32+00:00","article_modified_time":"2024-11-01T11:44:43+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\/35188\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/35188\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"kotlin coding test course, assign meeting rooms","datePublished":"2024-11-01T09:36:32+00:00","dateModified":"2024-11-01T11:44:43+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/35188\/"},"wordCount":383,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin coding test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/35188\/","url":"https:\/\/atmokpo.com\/w\/35188\/","name":"kotlin coding test course, assign meeting rooms - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:36:32+00:00","dateModified":"2024-11-01T11:44:43+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/35188\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/35188\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/35188\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"kotlin coding test course, assign meeting rooms"}]},{"@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\/35188","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=35188"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35188\/revisions"}],"predecessor-version":[{"id":35189,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35188\/revisions\/35189"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=35188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=35188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=35188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}