{"id":34926,"date":"2024-11-01T09:33:43","date_gmt":"2024-11-01T09:33:43","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34926"},"modified":"2024-11-01T12:56:52","modified_gmt":"2024-11-01T12:56:52","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-lets-try-ddr","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34926\/","title":{"rendered":"Kotlin Coding Test, Let&#8217;s try DDR"},"content":{"rendered":"<div class=\"blog-post\">\n<p>In this post, we will discuss a problem related to the &#8216;DDR&#8217; game, which is frequently presented as one of the algorithm problems for job interviews. This problem involves basic array manipulation and requires algorithmic thinking, making it very helpful for coding test preparation. We will examine the problem definition and the process of solving it in detail.<\/p>\n<h2>Problem Definition<\/h2>\n<p>You are a fan of the &#8216;DDR (Dance Dance Revolution)&#8217; game. In this game, arrows appear in various directions (up, down, left, right) on a rectangular step pad. The step pad is composed of a <strong>N * N<\/strong> grid. Arrows can appear at various positions on the grid, and according to certain rules, the grid is filled, and the arrows must be compressed upwards.<\/p>\n<p>You need to solve the problem of returning the compressed state based on the given initial state of the DDR step pad. The following rules apply:<\/p>\n<ul>\n<li>The game pad is of size <strong>N * N<\/strong>, and each position is represented by 0 (empty) or 1 (arrow).<\/li>\n<li>You must return the arrows that appear by compressing downwards in all columns. In other words, you need to push down by column.<\/li>\n<\/ul>\n<h2>Input and Output Format<\/h2>\n<p><strong>Input:<\/strong><\/p>\n<ol>\n<li>The first line contains the size of the step pad <strong>N<\/strong> (1 \u2264 N \u2264 100).<\/li>\n<li>The next <strong>N<\/strong> lines contain the state of the step pad. Each consists of <strong>N<\/strong> space-separated numbers made up of <strong>0<\/strong> and <strong>1<\/strong>.<\/li>\n<\/ol>\n<p><strong>Output:<\/strong><\/p>\n<p>Print the compressed state of the step pad over <strong>N<\/strong> lines. Each line consists of <strong>0<\/strong> and <strong>1<\/strong>, separated by spaces.<\/p>\n<h2>Example<\/h2>\n<h3>Input<\/h3>\n<pre>\n    5\n    0 0 0 0 0\n    1 0 1 0 0\n    1 1 0 1 0\n    0 0 0 1 1\n    0 0 0 0 0\n    <\/pre>\n<h3>Output<\/h3>\n<pre>\n    0 0 0 0 0\n    0 0 1 1 1\n    1 1 1 0 0\n    1 0 0 0 0\n    1 0 0 0 0\n    <\/pre>\n<h2>Problem Solving Process<\/h2>\n<p>Now, let&#8217;s plan the algorithm to solve the given problem. This problem requires us to implement the process of compressing downwards by column from the given grid. Let&#8217;s approach it step by step.<\/p>\n<h3>Step 1: Choosing the Data Structure<\/h3>\n<p>We will use a 2D array to store each input in a workspace. I will create a list for each column to count the number of 1s by checking each scene.<\/p>\n<h3>Step 2: Implementing the Compression Logic<\/h3>\n<p>We will check each column individually to count the number of 1s and perform the compression in a way that aligns the structure downwards. To do this, we will place 1s from the bottom in a newly structured array and fill the rest with 0s.<\/p>\n<h3>Step 3: Writing Kotlin Code<\/h3>\n<p>Now, let&#8217;s implement the above process in Kotlin. Here is the implemented code:<\/p>\n<pre>\n    fun compressDDRPads(n: Int, pads: Array<intarray>): Array<intarray> {\n        \/\/ Initialize a 2D array to store the result\n        val result = Array(n) { IntArray(n) }\n\n        \/\/ Iterate through each column to compress downwards\n        for (j in 0 until n) {\n            var count = 0\n\n            \/\/ Loop through the column to count the number of 1s\n            for (i in 0 until n) {\n                if (pads[i][j] == 1) {\n                    count++\n                }\n            }\n\n            \/\/ Fill the compressed result from the bottom\n            for (i in n - 1 downTo n - count) {\n                result[i][j] = 1\n            }\n        }\n\n        return result\n    }\n\n    \/\/ Example input\n    fun main() {\n        val n = 5\n        val pads = arrayOf(\n            intArrayOf(0, 0, 0, 0, 0),\n            intArrayOf(1, 0, 1, 0, 0),\n            intArrayOf(1, 1, 0, 1, 0),\n            intArrayOf(0, 0, 0, 1, 1),\n            intArrayOf(0, 0, 0, 0, 0)\n        )\n\n        val compressedPads = compressDDRPads(n, pads)\n\n        \/\/ Print the result\n        for (row in compressedPads) {\n            println(row.joinToString(\" \"))\n        }\n    }\n    <\/intarray><\/intarray><\/pre>\n<h2>Conclusion<\/h2>\n<p>In this post, we explored the process of solving the DDR problem using Kotlin. We found that understanding algorithmic thinking and data structures is crucial in the problem-solving process. By repeatedly practicing such problems in actual coding tests, you will find it easier to solve them. I hope to deepen my coding skills through various algorithm problems in the future.<\/p>\n<h2>References<\/h2>\n<ul>\n<li><a href=\"https:\/\/kotlinlang.org\/docs\/home.html\">Kotlin Official Documentation<\/a><\/li>\n<li><a href=\"https:\/\/www.geeksforgeeks.org\/\">GeeksforGeeks<\/a> &#8211; Algorithms and Data Structures<\/li>\n<li><a href=\"https:\/\/www.hackerrank.com\/\">HackerRank<\/a> &#8211; Coding Practice Problems<\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we will discuss a problem related to the &#8216;DDR&#8217; game, which is frequently presented as one of the algorithm problems for job interviews. This problem involves basic array manipulation and requires algorithmic thinking, making it very helpful for coding test preparation. We will examine the problem definition and the process of solving &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34926\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Kotlin Coding Test, 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":[106],"tags":[],"class_list":["post-34926","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, 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\/34926\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Kotlin Coding Test, Let&#039;s try DDR - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this post, we will discuss a problem related to the &#8216;DDR&#8217; game, which is frequently presented as one of the algorithm problems for job interviews. This problem involves basic array manipulation and requires algorithmic thinking, making it very helpful for coding test preparation. We will examine the problem definition and the process of solving &hellip; \ub354 \ubcf4\uae30 &quot;Kotlin Coding Test, Let&#8217;s try DDR&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34926\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:33:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T12:56:52+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\/34926\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34926\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Kotlin Coding Test, Let&#8217;s try DDR\",\"datePublished\":\"2024-11-01T09:33:43+00:00\",\"dateModified\":\"2024-11-01T12:56:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34926\/\"},\"wordCount\":475,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin coding test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34926\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34926\/\",\"name\":\"Kotlin Coding Test, Let's try DDR - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:33:43+00:00\",\"dateModified\":\"2024-11-01T12:56:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34926\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34926\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34926\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Kotlin Coding Test, 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":"Kotlin Coding Test, 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\/34926\/","og_locale":"ko_KR","og_type":"article","og_title":"Kotlin Coding Test, Let's try DDR - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this post, we will discuss a problem related to the &#8216;DDR&#8217; game, which is frequently presented as one of the algorithm problems for job interviews. This problem involves basic array manipulation and requires algorithmic thinking, making it very helpful for coding test preparation. We will examine the problem definition and the process of solving &hellip; \ub354 \ubcf4\uae30 \"Kotlin Coding Test, Let&#8217;s try DDR\"","og_url":"https:\/\/atmokpo.com\/w\/34926\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:33:43+00:00","article_modified_time":"2024-11-01T12:56:52+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\/34926\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34926\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Kotlin Coding Test, Let&#8217;s try DDR","datePublished":"2024-11-01T09:33:43+00:00","dateModified":"2024-11-01T12:56:52+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34926\/"},"wordCount":475,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin coding test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34926\/","url":"https:\/\/atmokpo.com\/w\/34926\/","name":"Kotlin Coding Test, Let's try DDR - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:33:43+00:00","dateModified":"2024-11-01T12:56:52+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34926\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34926\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34926\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Kotlin Coding Test, 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\/34926","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=34926"}],"version-history":[{"count":2,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34926\/revisions"}],"predecessor-version":[{"id":38123,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34926\/revisions\/38123"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}