{"id":33287,"date":"2024-11-01T09:15:10","date_gmt":"2024-11-01T09:15:10","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33287"},"modified":"2024-11-01T11:39:20","modified_gmt":"2024-11-01T11:39:20","slug":"java-coding-test-course-lets-try-ddr","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33287\/","title":{"rendered":"Java Coding Test Course, Let&#8217;s Try DDR"},"content":{"rendered":"<article>\n<p>\n        Recently, algorithm problems have become one of the important factors in the job market. Understanding algorithms and data structures is essential, especially for software engineering positions. In this course, we will address algorithm problems under the topic &#8220;DDR (Dance Dance Revolution)&#8221;. DDR is a dance game where you need to step on the designated panels within a given time. We will transform this into a programming problem to study algorithms.\n    <\/p>\n<h2>Problem Description<\/h2>\n<p>\n        You have participated in the DDR challenge. Given the order of the panels that appear on the screen, you must step on them accurately. The panels are indicated by integers from 1 to 9, where 1 is the bottom left, 2 is the bottom center, 3 is the bottom right, 4 is the middle left, 5 is the center, 6 is the middle right, 7 is the top left, 8 is the top center, and 9 is the top right.<\/p>\n<p>        The time and distance to step on the panels may vary depending on where you currently have your feet. Therefore, you need to find the optimal path.\n    <\/p>\n<h3>Input Format<\/h3>\n<p>\n        The first line contains the number of panels N (1 \u2264 N \u2264 1000). The second line provides N panels, with each panel represented by an integer between 1 and 9.\n    <\/p>\n<h3>Output Format<\/h3>\n<p>\n        Output the minimum time required to step on all the panels.\n    <\/p>\n<h2>Example Problem<\/h2>\n<pre>\n    <code>\n    Input:\n    5\n    1 3 5 7 9\n\n    Output:\n    8\n    <\/code>\n    <\/pre>\n<h2>Problem Solving Process<\/h2>\n<h3>Step 1: Define Panel Coordinates<\/h3>\n<p>\n        First, we need to define the positions of the panels. We can calculate the distances between the panels using a 2D array as follows.\n    <\/p>\n<pre>\n    <code>\n    \/\/ Define the positions of the panels as (row, column)\n    int[][] position = {\n        {3, 1}, \/\/ 1\n        {2, 1}, \/\/ 2\n        {1, 1}, \/\/ 3\n        {3, 2}, \/\/ 4\n        {2, 2}, \/\/ 5\n        {1, 2}, \/\/ 6\n        {3, 3}, \/\/ 7\n        {2, 3}, \/\/ 8\n        {1, 3}  \/\/ 9\n    };\n    <\/code>\n    <\/pre>\n<h3>Step 2: Implement Distance Calculation Function<\/h3>\n<p>\n        We will use the Manhattan distance for the distance calculation. The Manhattan distance between two points (x1, y1) and (x2, y2) is defined as |x1 &#8211; x2| + |y1 &#8211; y2|. Let&#8217;s implement this as a Java function.\n    <\/p>\n<pre>\n    <code>\n    public int calculateDistance(int a, int b) {\n        int x1 = position[a - 1][0];\n        int y1 = position[a - 1][1];\n        int x2 = position[b - 1][0];\n        int y2 = position[b - 1][1];\n        \n        return Math.abs(x1 - x2) + Math.abs(y1 - y2);\n    }\n    <\/code>\n    <\/pre>\n<h3>Step 3: Implement Main Logic<\/h3>\n<p>\n        Now, we will implement the main logic to calculate the optimal path to step on each panel once. We will calculate the distance between the current position and the target panel, then accumulate the minimum distance.\n    <\/p>\n<pre>\n    <code>\n    public int minTime(int[] steps) {\n        int totalTime = 0;\n        int currentPosition = 5; \/\/ Initial panel is at position 5 (center)\n\n        for (int step : steps) {\n            totalTime += calculateDistance(currentPosition, step);\n            currentPosition = step; \/\/ Update current position\n        }\n        return totalTime;\n    }\n    <\/code>\n    <\/pre>\n<h3>Step 4: Full Code<\/h3>\n<p>\n        Finally, we will write the complete code to receive panel information and calculate the minimum time.\n    <\/p>\n<pre>\n    <code>\n    import java.util.Scanner;\n\n    public class Main {\n        static int[][] position = {\n            {3, 1}, \/\/ 1\n            {2, 1}, \/\/ 2\n            {1, 1}, \/\/ 3\n            {3, 2}, \/\/ 4\n            {2, 2}, \/\/ 5\n            {1, 2}, \/\/ 6\n            {3, 3}, \/\/ 7\n            {2, 3}, \/\/ 8\n            {1, 3}  \/\/ 9\n        };\n\n        public static void main(String[] args) {\n            Scanner scanner = new Scanner(System.in);\n            int N = scanner.nextInt();\n            int[] steps = new int[N];\n\n            for (int i = 0; i < N; i++) {\n                steps[i] = scanner.nextInt();\n            }\n\n            System.out.println(minTime(steps));\n        }\n\n        public static int minTime(int[] steps) {\n            int totalTime = 0;\n            int currentPosition = 5; \/\/ Initial panel is at position 5 (center)\n\n            for (int step : steps) {\n                totalTime += calculateDistance(currentPosition, step);\n                currentPosition = step; \/\/ Update current position\n            }\n            return totalTime;\n        }\n\n        public static int calculateDistance(int a, int b) {\n            int x1 = position[a - 1][0];\n            int y1 = position[a - 1][1];\n            int x2 = position[b - 1][0];\n            int y2 = position[b - 1][1];\n            \n            return Math.abs(x1 - x2) + Math.abs(y1 - y2);\n        }\n    }\n    <\/code>\n    <\/pre>\n<h2>Conclusion<\/h2>\n<p>\n        In this course, we learned about the positions of the panels and distance calculations through a simple algorithm problem. This type of problem often appears in actual coding tests. By solving various algorithm problems, you can naturally enhance your understanding of data structures and algorithms. We hope you continue to solve many problems and gain experience!\n    <\/p>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>Recently, algorithm problems have become one of the important factors in the job market. Understanding algorithms and data structures is essential, especially for software engineering positions. In this course, we will address algorithm problems under the topic &#8220;DDR (Dance Dance Revolution)&#8221;. DDR is a dance game where you need to step on the designated panels &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33287\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, Let&#8217;s Try DDR&#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":[139],"tags":[],"class_list":["post-33287","post","type-post","status-publish","format-standard","hentry","category-java-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java Coding Test Course, Let&#039;s Try DDR - \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\/33287\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Coding Test Course, Let&#039;s Try DDR - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Recently, algorithm problems have become one of the important factors in the job market. Understanding algorithms and data structures is essential, especially for software engineering positions. In this course, we will address algorithm problems under the topic &#8220;DDR (Dance Dance Revolution)&#8221;. DDR is a dance game where you need to step on the designated panels &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, Let&#8217;s Try DDR&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33287\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:15:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:39:20+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\/33287\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33287\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, Let&#8217;s Try DDR\",\"datePublished\":\"2024-11-01T09:15:10+00:00\",\"dateModified\":\"2024-11-01T11:39:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33287\/\"},\"wordCount\":408,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33287\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33287\/\",\"name\":\"Java Coding Test Course, Let's Try DDR - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:15:10+00:00\",\"dateModified\":\"2024-11-01T11:39:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33287\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33287\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33287\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, Let&#8217;s Try DDR\"}]},{\"@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":"Java Coding Test Course, Let's Try DDR - \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\/33287\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, Let's Try DDR - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Recently, algorithm problems have become one of the important factors in the job market. Understanding algorithms and data structures is essential, especially for software engineering positions. In this course, we will address algorithm problems under the topic &#8220;DDR (Dance Dance Revolution)&#8221;. DDR is a dance game where you need to step on the designated panels &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, Let&#8217;s Try DDR\"","og_url":"https:\/\/atmokpo.com\/w\/33287\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:15:10+00:00","article_modified_time":"2024-11-01T11:39:20+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\/33287\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33287\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, Let&#8217;s Try DDR","datePublished":"2024-11-01T09:15:10+00:00","dateModified":"2024-11-01T11:39:20+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33287\/"},"wordCount":408,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33287\/","url":"https:\/\/atmokpo.com\/w\/33287\/","name":"Java Coding Test Course, Let's Try DDR - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:15:10+00:00","dateModified":"2024-11-01T11:39:20+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33287\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33287\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33287\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, Let&#8217;s Try DDR"}]},{"@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\/33287","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=33287"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33287\/revisions"}],"predecessor-version":[{"id":33288,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33287\/revisions\/33288"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}