{"id":33506,"date":"2024-11-01T09:17:15","date_gmt":"2024-11-01T09:17:15","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33506"},"modified":"2024-11-01T11:38:15","modified_gmt":"2024-11-01T11:38:15","slug":"java-coding-test-course-finding-minimum-value-2","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33506\/","title":{"rendered":"Java Coding Test Course, Finding Minimum Value 2"},"content":{"rendered":"<p><body><\/p>\n<article>\n<section>\n<h2>Problem Description<\/h2>\n<p>\n                There is a given integer array. You need to find the minimum value within a specific range in this array.<\/p>\n<p>                Moreover, this range is dynamically provided and can be requested for multiple queries.<\/p>\n<p>                In other words, given specific indices i and j of the array,<\/p>\n<p>                you need to find the minimum value between i and j.<\/p>\n<p>                The goal of this course is to design and implement an efficient algorithm to solve this problem.\n            <\/p>\n<h3>Problem Format<\/h3>\n<p>\n                Input: An integer array nums and a list of queries queries.<br \/>\n                &#8211; nums: An array of n integers (0 \u2264 n \u2264 10^5, -10^9 \u2264 nums[i] \u2264 10^9)<br \/>\n                &#8211; queries: A list containing multiple pairs (i, j) (0 \u2264 queries.length \u2264 10^5, 0 \u2264 i \u2264 j &lt; n)<br \/>\n                Output: Return a list of minimum values for each query.\n            <\/p>\n<\/section>\n<section>\n<h2>Example Problems<\/h2>\n<h3>Example 1<\/h3>\n<p><strong>Input:<\/strong><\/p>\n<pre>\n            nums = [2, 0, 3, 5, 1]\n            queries = [[0, 2], [1, 4], [0, 4]]\n            <\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre>\n            [0, 1, 0]\n            <\/pre>\n<h3>Example 2<\/h3>\n<p><strong>Input:<\/strong><\/p>\n<pre>\n            nums = [1, 2, 3, 4, 5]\n            queries = [[0, 0], [0, 4], [2, 3]]\n            <\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre>\n            [1, 1, 3]\n            <\/pre>\n<\/section>\n<section>\n<h2>Solution Strategy<\/h2>\n<p>\n                There are several approaches to solving this problem.<\/p>\n<p>                The simplest way is to use linear search for each query.<\/p>\n<p>                However, this method has a worst-case time complexity of O(m * n),<\/p>\n<p>                so a more efficient method is required.<\/p>\n<p>                We will utilize data structures such as Segment Tree or Sparse Table<\/p>\n<p>                to find the minimum value for each query in O(log n) or O(1) time complexity.\n            <\/p>\n<\/section>\n<section>\n<h2>Using Segment Tree<\/h2>\n<p>\n                A Segment Tree is a data structure that efficiently handles range queries on a given array.<\/p>\n<p>                With this, we can build the Segment Tree in O(n) and process each query in O(log n).<\/p>\n<p>                Here is how to construct the Segment Tree and handle queries.\n            <\/p>\n<h3>Segment Tree Implementation<\/h3>\n<pre>\n            \/\/ Segment Tree class\n            class SegmentTree {\n                private int[] tree;\n                private int n;\n\n                public SegmentTree(int[] nums) {\n                    n = nums.length;\n                    tree = new int[4 * n]; \/\/ Sufficiently sized tree array\n                    build(nums, 0, 0, n - 1);\n                }\n\n                private void build(int[] nums, int node, int start, int end) {\n                    if (start == end) {\n                        tree[node] = nums[start]; \/\/ Store value at leaf node\n                    } else {\n                        int mid = (start + end) \/ 2;\n                        build(nums, 2 * node + 1, start, mid);\n                        build(nums, 2 * node + 2, mid + 1, end);\n                        tree[node] = Math.min(tree[2 * node + 1], tree[2 * node + 2]); \n                    }\n                }\n\n                public int query(int L, int R) {\n                    return query(0, 0, n - 1, L, R);\n                }\n\n                private int query(int node, int start, int end, int L, int R) {\n                    if (R &lt; start || end &lt; L) { \n                        return Integer.MAX_VALUE; \/\/ Return infinity if not in range\n                    }\n                    if (L &lt;= start &amp;&amp; end &lt;= R) { \n                        return tree[node]; \/\/ Return node value if in range\n                    }\n                    int mid = (start + end) \/ 2;\n                    int leftMin = query(2 * node + 1, start, mid, L, R);\n                    int rightMin = query(2 * node + 2, mid + 1, end, L, R);\n                    return Math.min(leftMin, rightMin); \/\/ Return minimum of both children\n                }\n            }\n            <\/pre>\n<\/section>\n<section>\n<h2>Final Implementation and Experiments<\/h2>\n<p>\n                Now we will implement the main function that processes each query and returns the result.<\/p>\n<p>                By allowing users to request queries, we can efficiently retrieve the minimum value.<\/p>\n<p>                The final implementation is as follows.\n            <\/p>\n<pre>\n            public class MinValueFinder {\n                public int[] minInRange(int[] nums, int[][] queries) {\n                    SegmentTree segmentTree = new SegmentTree(nums); \n                    int[] results = new int[queries.length];\n\n                    for (int i = 0; i &lt; queries.length; i++) {\n                        results[i] = segmentTree.query(queries[i][0], queries[i][1]); \n                    }\n                    return results; \n                }\n            }\n            <\/pre>\n<\/section>\n<section>\n<h2>Time Complexity Analysis<\/h2>\n<p>\n                &#8211; Segment Tree Construction: O(n)<br \/>\n                &#8211; Each Query Processing: O(log n)<br \/>\n                The overall time complexity is O(n + m * log n). <br \/>\n                This is very efficient and can be sufficiently performed under restricted input conditions.\n            <\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>\n                In this course, we solved the problem of finding the minimum value in a specific range of a given array using a Segment Tree.<\/p>\n<p>                The Segment Tree can efficiently handle multiple queries and is frequently used data structure in large datasets.<\/p>\n<p>                I hope this enhances your problem-solving abilities.\n            <\/p>\n<\/section>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description There is a given integer array. You need to find the minimum value within a specific range in this array. Moreover, this range is dynamically provided and can be requested for multiple queries. In other words, given specific indices i and j of the array, you need to find the minimum value between &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33506\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, Finding Minimum Value 2&#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-33506","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, Finding Minimum Value 2 - \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\/33506\/\" \/>\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, Finding Minimum Value 2 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Problem Description There is a given integer array. You need to find the minimum value within a specific range in this array. Moreover, this range is dynamically provided and can be requested for multiple queries. In other words, given specific indices i and j of the array, you need to find the minimum value between &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, Finding Minimum Value 2&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33506\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:17:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:38:15+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\/33506\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33506\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, Finding Minimum Value 2\",\"datePublished\":\"2024-11-01T09:17:15+00:00\",\"dateModified\":\"2024-11-01T11:38:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33506\/\"},\"wordCount\":385,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33506\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33506\/\",\"name\":\"Java Coding Test Course, Finding Minimum Value 2 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:17:15+00:00\",\"dateModified\":\"2024-11-01T11:38:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33506\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33506\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33506\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, Finding Minimum Value 2\"}]},{\"@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, Finding Minimum Value 2 - \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\/33506\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, Finding Minimum Value 2 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Problem Description There is a given integer array. You need to find the minimum value within a specific range in this array. Moreover, this range is dynamically provided and can be requested for multiple queries. In other words, given specific indices i and j of the array, you need to find the minimum value between &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, Finding Minimum Value 2\"","og_url":"https:\/\/atmokpo.com\/w\/33506\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:17:15+00:00","article_modified_time":"2024-11-01T11:38:15+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\/33506\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33506\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, Finding Minimum Value 2","datePublished":"2024-11-01T09:17:15+00:00","dateModified":"2024-11-01T11:38:15+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33506\/"},"wordCount":385,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33506\/","url":"https:\/\/atmokpo.com\/w\/33506\/","name":"Java Coding Test Course, Finding Minimum Value 2 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:17:15+00:00","dateModified":"2024-11-01T11:38:15+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33506\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33506\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33506\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, Finding Minimum Value 2"}]},{"@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\/33506","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=33506"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33506\/revisions"}],"predecessor-version":[{"id":33507,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33506\/revisions\/33507"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}