{"id":35062,"date":"2024-11-01T09:35:10","date_gmt":"2024-11-01T09:35:10","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=35062"},"modified":"2024-11-01T11:45:07","modified_gmt":"2024-11-01T11:45:07","slug":"kotlin-coding-test-course-sliding-window","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/35062\/","title":{"rendered":"kotlin coding test course, sliding window"},"content":{"rendered":"<p><body><\/p>\n<p>One of the common problem types that appear in coding interviews is the Sliding Window technique. This technique is very useful when working with subsets of an array. In particular, it boasts excellent performance when calculating the sum, maximum, minimum, etc., of consecutive elements. In this article, we will explain the basic concept of the sliding window along with the process of solving practical problems in detail.<\/p>\n<h2>Problem Introduction<\/h2>\n<h3>Problem: Maximum Length of Subarray<\/h3>\n<p>There is a given integer array <code>nums<\/code> and an integer <code>k<\/code>. Your task is to find the length of the longest subarray in the <code>nums<\/code> array such that the sum of its consecutive elements is less than or equal to <code>k<\/code>. If such an array does not exist, return 0.<\/p>\n<h3>Example<\/h3>\n<pre>\n    Input: nums = [1, 2, 3, 4, 5], k = 5\n    Output: 2\n    Explanation: The length of [2, 3] or [1, 2] is a maximum of 2.\n    <\/pre>\n<h3>Approach to the Problem<\/h3>\n<p>This problem can be solved using the sliding window technique. This method involves traversing the array while using two pointers (start and end) to adjust the size of the window. The longest subarray satisfying the desired condition is found by adjusting the window size as needed.<\/p>\n<h2>Problem Solving Process<\/h2>\n<h3>Step 1: Initialize Pointers<\/h3>\n<p>First, initialize the start pointer <code>start<\/code> and the end pointer <code>end<\/code>. Set the start pointer to 0 and the end pointer to 0. Also, initialize a variable <code>sum<\/code> to keep track of the sum of the array.<\/p>\n<h3>Step 2: Expand the Window with a Loop<\/h3>\n<p>Move the end pointer <code>end<\/code> to the end of the array to expand the window. Add the current element to <code>sum<\/code>, and if <code>sum<\/code> exceeds <code>k<\/code>, move the start pointer <code>start<\/code> to adjust <code>sum<\/code> to be less than or equal to <code>k<\/code>.<\/p>\n<h3>Step 3: Update Maximum Length<\/h3>\n<p>When each window is less than or equal to <code>k<\/code>, calculate the current length and store it in the maximum length variable.<\/p>\n<h3>Step 4: Return Result<\/h3>\n<p>After completing all the processes, return the maximum length.<\/p>\n<h2>Kotlin Implementation<\/h2>\n<pre><code class=\"kotlin\">\nfun maxLengthSubArray(nums: IntArray, k: Int): Int {\n    var start = 0\n    var end = 0\n    var sum = 0\n    var maxLength = 0\n\n    while (end &lt; nums.size) {\n        sum += nums[end]\n\n        while (sum &gt; k &amp;&amp; start &lt;= end) {\n            sum -= nums[start]\n            start++\n        }\n\n        maxLength = Math.max(maxLength, end - start + 1)\n        end++\n    }\n\n    return maxLength\n}\n<\/code><\/pre>\n<h2>Result Verification<\/h2>\n<p>After executing the code to solve the problem, verify the results with various test cases.<\/p>\n<pre><code class=\"kotlin\">\nfun main() {\n    println(maxLengthSubArray(intArrayOf(1, 2, 3, 4, 5), 5)) \/\/ Output: 2\n    println(maxLengthSubArray(intArrayOf(1, 2, 3, 4, 5), 11)) \/\/ Output: 5\n    println(maxLengthSubArray(intArrayOf(5, 4, 3, 2, 1), 3)) \/\/ Output: 1\n    println(maxLengthSubArray(intArrayOf(1, 2, 3, 4, 5), 0)) \/\/ Output: 0\n}\n<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we covered the process of solving the maximum length subarray problem using the sliding window technique. The sliding window technique is a powerful tool for efficiently solving array or string problems. Practice this technique through various problems.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the common problem types that appear in coding interviews is the Sliding Window technique. This technique is very useful when working with subsets of an array. In particular, it boasts excellent performance when calculating the sum, maximum, minimum, etc., of consecutive elements. In this article, we will explain the basic concept of the &hellip; <a href=\"https:\/\/atmokpo.com\/w\/35062\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;kotlin coding test course, sliding window&#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-35062","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, sliding window - \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\/35062\/\" \/>\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, sliding window - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"One of the common problem types that appear in coding interviews is the Sliding Window technique. This technique is very useful when working with subsets of an array. In particular, it boasts excellent performance when calculating the sum, maximum, minimum, etc., of consecutive elements. In this article, we will explain the basic concept of the &hellip; \ub354 \ubcf4\uae30 &quot;kotlin coding test course, sliding window&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/35062\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:35:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:45:07+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\/35062\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35062\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"kotlin coding test course, sliding window\",\"datePublished\":\"2024-11-01T09:35:10+00:00\",\"dateModified\":\"2024-11-01T11:45:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35062\/\"},\"wordCount\":353,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin coding test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/35062\/\",\"url\":\"https:\/\/atmokpo.com\/w\/35062\/\",\"name\":\"kotlin coding test course, sliding window - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:35:10+00:00\",\"dateModified\":\"2024-11-01T11:45:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35062\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/35062\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/35062\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"kotlin coding test course, sliding window\"}]},{\"@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, sliding window - \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\/35062\/","og_locale":"ko_KR","og_type":"article","og_title":"kotlin coding test course, sliding window - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"One of the common problem types that appear in coding interviews is the Sliding Window technique. This technique is very useful when working with subsets of an array. In particular, it boasts excellent performance when calculating the sum, maximum, minimum, etc., of consecutive elements. In this article, we will explain the basic concept of the &hellip; \ub354 \ubcf4\uae30 \"kotlin coding test course, sliding window\"","og_url":"https:\/\/atmokpo.com\/w\/35062\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:35:10+00:00","article_modified_time":"2024-11-01T11:45:07+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\/35062\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/35062\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"kotlin coding test course, sliding window","datePublished":"2024-11-01T09:35:10+00:00","dateModified":"2024-11-01T11:45:07+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/35062\/"},"wordCount":353,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin coding test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/35062\/","url":"https:\/\/atmokpo.com\/w\/35062\/","name":"kotlin coding test course, sliding window - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:35:10+00:00","dateModified":"2024-11-01T11:45:07+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/35062\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/35062\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/35062\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"kotlin coding test course, sliding window"}]},{"@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\/35062","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=35062"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35062\/revisions"}],"predecessor-version":[{"id":35063,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35062\/revisions\/35063"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=35062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=35062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=35062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}