{"id":33414,"date":"2024-11-01T09:16:17","date_gmt":"2024-11-01T09:16:17","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33414"},"modified":"2024-11-01T11:38:48","modified_gmt":"2024-11-01T11:38:48","slug":"java-coding-test-course-finding-the-order-of-permutations","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33414\/","title":{"rendered":"Java Coding Test Course, Finding the Order of Permutations"},"content":{"rendered":"<p><body><\/p>\n<article>\n<header>\n<p>This article aims to address the commonly asked problem of &#8220;Finding the Order of a Permutation&#8221; in coding tests using Java. We will detail the necessary theories, approaches, and code examples required to solve this problem.<\/p>\n<\/header>\n<section>\n<h2>Problem Definition<\/h2>\n<p>This problem involves determining the position of a specific number&#8217;s permutation in a given number array. For example, when the array is <code>[1, 2, 3]<\/code>, all permutations are listed as follows:<\/p>\n<ul>\n<li>1, 2, 3<\/li>\n<li>1, 3, 2<\/li>\n<li>2, 1, 3<\/li>\n<li>2, 3, 1<\/li>\n<li>3, 1, 2<\/li>\n<li>3, 2, 1<\/li>\n<\/ul>\n<p>For example, for the number <code>2<\/code>, when the permutation is <code>2, 1, 3<\/code>, this permutation will be in the 3rd position. We will deduce from this information to find out the position of the given number&#8217;s permutation.<\/p>\n<\/section>\n<section>\n<h2>Problem Approach<\/h2>\n<p>To solve this problem, you can follow these steps:<\/p>\n<ol>\n<li>Calculate the total number of permutations based on the length of the given array.<\/li>\n<li>Calculate the position based on the target permutation using the necessary formulas at each step.<\/li>\n<li>Write a recursive function to determine the position of the permutation at each step.<\/li>\n<\/ol>\n<\/section>\n<section>\n<h2>Calculating the Number of Permutations<\/h2>\n<p>When the length of the given number array is <code>n<\/code>, there are <code>n!<\/code> (n factorial) permutations. This is the product of all integers from 1 to <code>n<\/code>.<\/p>\n<p>For example, if the length of the array is 3, the number of permutations is <code>3! = 6<\/code>.<\/p>\n<\/section>\n<section>\n<h2>Negative Calculation and Recursion for Order Calculation<\/h2>\n<p>To calculate the order, we need to consider the cases after a specific number has been selected. For instance, if we assume we choose <code>1<\/code>, we recursively call the remaining numbers&#8217; permutations to compute the order.<\/p>\n<p>This approach helps us find out how many permutations are possible for each number and perform the calculations.<\/p>\n<\/section>\n<section>\n<h2>Java Code Implementation<\/h2>\n<p>Below is the Java code to solve the &#8220;Finding the Order of a Permutation&#8221; problem:<\/p>\n<pre><code>\npublic class PermutationOrder {\n    \n    public static void main(String[] args) {\n        int[] numbers = {1, 2, 3}; \/\/ Given array\n        int[] target = {2, 1, 3};   \/\/ Target permutation to calculate the order\n        int rank = findRank(numbers, target);\n        System.out.println(\"Order of the target permutation: \" + rank);\n    }\n    \n    public static int findRank(int[] numbers, int[] target) {\n        int n = numbers.length;\n        boolean[] used = new boolean[n];\n        return getRank(numbers, target, used, 0);\n    }\n    \n    private static int getRank(int[] numbers, int[] target, boolean[] used, int index) {\n        int rank = 1; \/\/ Default order starts from 1\n        int n = numbers.length;\n        \n        for (int i = 0; i &lt; n; i++) {\n            \/\/ If the number is smaller than the target number\n            if (!used[i]) {\n                for (int j = 0; j &lt; target[index]; j++) {\n                    if (j == numbers[i]) {\n                        break;\n                    }\n                    rank += factorial(n - index - 1); \/\/ Add (n-1)! for each smaller number\n                }\n            }\n            if (target[index] == numbers[i]) {\n                used[i] = true; \/\/ Use that number\n                break;\n            }\n        }\n        \n        if (index &lt; n - 1) {\n            rank += getRank(numbers, target, used, index + 1); \/\/ Recursive call for the next index\n        }\n        \n        return rank;\n    }\n\n    private static int factorial(int n) {\n        if (n == 0) return 1;\n        int result = 1;\n        for (int i = 1; i &lt;= n; i++) {\n            result *= i;\n        }\n        return result;\n    }\n}\n            <\/code><\/pre>\n<p>This code uses a recursive approach to calculate the order based on the given number array and target permutation. The main function <code>getRank<\/code> incrementally checks each number in the target permutation and determines the order based on combinations with other numbers.<\/p>\n<\/section>\n<section>\n<h2>Example Test Cases<\/h2>\n<p>After writing the code, you can validate the results through several examples as follows:<\/p>\n<ul>\n<li>Input: <code>[1, 2, 3]<\/code>, Target: <code>[2, 1, 3]<\/code> \u2192 Output: 3<\/li>\n<li>Input: <code>[1, 2, 3]<\/code>, Target: <code>[1, 3, 2]<\/code> \u2192 Output: 2<\/li>\n<li>Input: <code>[1, 2, 3]<\/code>, Target: <code>[3, 2, 1]<\/code> \u2192 Output: 6<\/li>\n<\/ul>\n<p>You can iterate as much as needed using various arrays and target permutations with the above code to obtain the correct output. Since various test cases can be generated just from the combinations of permutations, it is essential to evaluate the accuracy and efficiency of the algorithm.<\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>In this article, we addressed the problem of finding the order of permutations using Java. We emphasized how the combination of recursive approaches, the calculation of the number of permutations, and the algorithm for checking the exact order effectively solved the problem. This should enhance the understanding of coding tests and greatly aid in solving a wider range of problems.<\/p>\n<\/section>\n<footer>\n<p>If you found this article helpful, please share it. If you have questions or need further discussion, please leave a comment.<\/p>\n<\/footer>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article aims to address the commonly asked problem of &#8220;Finding the Order of a Permutation&#8221; in coding tests using Java. We will detail the necessary theories, approaches, and code examples required to solve this problem. Problem Definition This problem involves determining the position of a specific number&#8217;s permutation in a given number array. For &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33414\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, Finding the Order of Permutations&#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-33414","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 the Order of Permutations - \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\/33414\/\" \/>\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 the Order of Permutations - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"This article aims to address the commonly asked problem of &#8220;Finding the Order of a Permutation&#8221; in coding tests using Java. We will detail the necessary theories, approaches, and code examples required to solve this problem. Problem Definition This problem involves determining the position of a specific number&#8217;s permutation in a given number array. For &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, Finding the Order of Permutations&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33414\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:16:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:38:48+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\/33414\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33414\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, Finding the Order of Permutations\",\"datePublished\":\"2024-11-01T09:16:17+00:00\",\"dateModified\":\"2024-11-01T11:38:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33414\/\"},\"wordCount\":479,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33414\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33414\/\",\"name\":\"Java Coding Test Course, Finding the Order of Permutations - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:16:17+00:00\",\"dateModified\":\"2024-11-01T11:38:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33414\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33414\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33414\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, Finding the Order of Permutations\"}]},{\"@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 the Order of Permutations - \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\/33414\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, Finding the Order of Permutations - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"This article aims to address the commonly asked problem of &#8220;Finding the Order of a Permutation&#8221; in coding tests using Java. We will detail the necessary theories, approaches, and code examples required to solve this problem. Problem Definition This problem involves determining the position of a specific number&#8217;s permutation in a given number array. For &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, Finding the Order of Permutations\"","og_url":"https:\/\/atmokpo.com\/w\/33414\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:16:17+00:00","article_modified_time":"2024-11-01T11:38:48+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\/33414\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33414\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, Finding the Order of Permutations","datePublished":"2024-11-01T09:16:17+00:00","dateModified":"2024-11-01T11:38:48+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33414\/"},"wordCount":479,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33414\/","url":"https:\/\/atmokpo.com\/w\/33414\/","name":"Java Coding Test Course, Finding the Order of Permutations - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:16:17+00:00","dateModified":"2024-11-01T11:38:48+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33414\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33414\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33414\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, Finding the Order of Permutations"}]},{"@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\/33414","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=33414"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33414\/revisions"}],"predecessor-version":[{"id":33415,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33414\/revisions\/33415"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}