{"id":35162,"date":"2024-11-01T09:36:16","date_gmt":"2024-11-01T09:36:16","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=35162"},"modified":"2024-11-01T09:37:21","modified_gmt":"2024-11-01T09:37:21","slug":"%ec%bd%94%ed%8b%80%eb%a6%b0-coding-test-course-go-fast-with-time-machine","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/35162\/","title":{"rendered":"Kotlin Coding Test Course, Go Fast with Time Machine"},"content":{"rendered":"<p><body><\/p>\n<h2>Problem Description<\/h2>\n<p>Imagine! You, from the future, decide to travel to a specific time using a time machine. However, this time machine can only operate through a complex algorithm. The problem is to calculate the minimum number of jumps needed to reach the given time.<\/p>\n<h3>Problem Definition<\/h3>\n<p>Two integers S and E are given. S is the starting time and E is the arrival time. The time machine operates according to the following rules:<\/p>\n<ul>\n<li>From the current time, you can jump to the next time by performing +1, +2, or *2 operations.<\/li>\n<li>Write a program to calculate and output the minimum number of jumps taken by the time machine to operate.<\/li>\n<\/ul>\n<h3>Input<\/h3>\n<p>In the first line, two integers S (1 \u2264 S \u2264 10<sup>5<\/sup>) and E (1 \u2264 E \u2264 10<sup>5<\/sup>) are given.<\/p>\n<h3>Output<\/h3>\n<p>Output the minimum number of jumps required for the time machine to reach E.<\/p>\n<h2>Example<\/h2>\n<pre>\n    <strong>Input:<\/strong>\n    4 7\n\n    <strong>Output:<\/strong>\n    2\n    <\/pre>\n<h2>Problem Solving Process<\/h2>\n<p>This problem can be solved using the BFS (Breadth-First Search) algorithm. BFS starts from a specific node and explores all nodes connected to it before exploring the nodes of the next layer. In this problem, each time zone can be represented as a node in a graph, while each jump can be represented as an edge.<\/p>\n<h3>Step-by-Step Solution<\/h3>\n<ol>\n<li><strong>Initialize the Queue:<\/strong> To perform BFS, first initialize the queue. Add the starting time S and the current jump count to the queue.<\/li>\n<li><strong>Visit Array:<\/strong> Create a visit array to record the times that have already been visited. This prevents visiting the same time multiple times.<\/li>\n<li><strong>Perform BFS:<\/strong> Remove a node from the queue and explore the next times by performing all possible jumps. If the next jump reaches the arrival time E, return the current jump count.<\/li>\n<li><strong>Termination Condition:<\/strong> If the queue becomes empty without reaching the arrival time, terminate the jump process.<\/li>\n<\/ol>\n<h3>Code Implementation<\/h3>\n<pre><code class=\"code\">\nfun minJumps(S: Int, E: Int): Int {\n    val queue: Queue<pair<int, int=\"\">&gt; = LinkedList()\n    val visited = BooleanArray(100001) \/\/ maximum time range 100000\n    queue.add(Pair(S, 0))\n    visited[S] = true\n\n    while (queue.isNotEmpty()) {\n        val (currentTime, jumps) = queue.poll()\n\n        \/\/ Reached the destination\n        if (currentTime == E) {\n            return jumps\n        }\n\n        \/\/ Next possible times\n        val nextTimes = listOf(currentTime + 1, currentTime + 2, currentTime * 2)\n\n        for (nextTime in nextTimes) {\n            if (nextTime in 1..100000 &amp;&amp; !visited[nextTime]) {\n                visited[nextTime] = true\n                queue.add(Pair(nextTime, jumps + 1))\n            }\n        }\n    }\n    return -1 \/\/ unreachable case\n}\n\nfun main() {\n    val input = readLine()!!.split(\" \")\n    val S = input[0].toInt()\n    val E = input[1].toInt()\n    println(minJumps(S, E))\n}\n    <\/pair<int,><\/code><\/pre>\n<h2>Time Complexity Analysis<\/h2>\n<p>The time complexity of this algorithm is O(n). Since all time zones will be visited once, performing BFS for up to 100,000 nodes is efficient.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this lecture, we explored how to apply the BFS algorithm to solve the time machine problem and calculate the shortest distance. Understanding and applying the advantages of implementing it in Kotlin as well as the basic principles of BFS will help you in coding tests. In the next session, we will prepare a lecture to explore other problems and more diverse algorithms!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description Imagine! You, from the future, decide to travel to a specific time using a time machine. However, this time machine can only operate through a complex algorithm. The problem is to calculate the minimum number of jumps needed to reach the given time. Problem Definition Two integers S and E are given. S &hellip; <a href=\"https:\/\/atmokpo.com\/w\/35162\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Kotlin Coding Test Course, Go Fast with Time Machine&#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-35162","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, Go Fast with Time Machine - \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\/35162\/\" \/>\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, Go Fast with Time Machine - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Problem Description Imagine! You, from the future, decide to travel to a specific time using a time machine. However, this time machine can only operate through a complex algorithm. The problem is to calculate the minimum number of jumps needed to reach the given time. Problem Definition Two integers S and E are given. S &hellip; \ub354 \ubcf4\uae30 &quot;Kotlin Coding Test Course, Go Fast with Time Machine&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/35162\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:36:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T09:37:21+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\/35162\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35162\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Kotlin Coding Test Course, Go Fast with Time Machine\",\"datePublished\":\"2024-11-01T09:36:16+00:00\",\"dateModified\":\"2024-11-01T09:37:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35162\/\"},\"wordCount\":396,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin coding test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/35162\/\",\"url\":\"https:\/\/atmokpo.com\/w\/35162\/\",\"name\":\"Kotlin Coding Test Course, Go Fast with Time Machine - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:36:16+00:00\",\"dateModified\":\"2024-11-01T09:37:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35162\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/35162\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/35162\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Kotlin Coding Test Course, Go Fast with Time Machine\"}]},{\"@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, Go Fast with Time Machine - \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\/35162\/","og_locale":"ko_KR","og_type":"article","og_title":"Kotlin Coding Test Course, Go Fast with Time Machine - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Problem Description Imagine! You, from the future, decide to travel to a specific time using a time machine. However, this time machine can only operate through a complex algorithm. The problem is to calculate the minimum number of jumps needed to reach the given time. Problem Definition Two integers S and E are given. S &hellip; \ub354 \ubcf4\uae30 \"Kotlin Coding Test Course, Go Fast with Time Machine\"","og_url":"https:\/\/atmokpo.com\/w\/35162\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:36:16+00:00","article_modified_time":"2024-11-01T09:37:21+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\/35162\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/35162\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Kotlin Coding Test Course, Go Fast with Time Machine","datePublished":"2024-11-01T09:36:16+00:00","dateModified":"2024-11-01T09:37:21+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/35162\/"},"wordCount":396,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin coding test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/35162\/","url":"https:\/\/atmokpo.com\/w\/35162\/","name":"Kotlin Coding Test Course, Go Fast with Time Machine - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:36:16+00:00","dateModified":"2024-11-01T09:37:21+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/35162\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/35162\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/35162\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Kotlin Coding Test Course, Go Fast with Time Machine"}]},{"@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\/35162","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=35162"}],"version-history":[{"count":2,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35162\/revisions"}],"predecessor-version":[{"id":35256,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35162\/revisions\/35256"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=35162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=35162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=35162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}