{"id":33295,"date":"2024-11-01T09:15:16","date_gmt":"2024-11-01T09:15:16","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33295"},"modified":"2024-11-01T11:39:18","modified_gmt":"2024-11-01T11:39:18","slug":"java-coding-test-course-finding-good-numbers","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33295\/","title":{"rendered":"Java Coding Test Course, &#8216;Finding Good Numbers&#8217;"},"content":{"rendered":"<p><body><\/p>\n<h2>Problem Description<\/h2>\n<p>\n        Given a number N, write a computer program that can transform N such that the sum of its digits is less than N.<br \/>\n        Here, a number where the sum of its digits is less than N is called a &#8220;good number&#8221;.<br \/>\n        In other words, this is an algorithm problem to find the largest number among all numbers less than N, where the sum of its digits is less than N.\n    <\/p>\n<h2>Example Problem<\/h2>\n<p>For example, if N is 23:<\/p>\n<ul>\n<li>22 (2 + 2 = 4) \u2192 &#8216;good number&#8217;<\/li>\n<li>21 (2 + 1 = 3) \u2192 &#8216;good number&#8217;<\/li>\n<li>20 (2 + 0 = 2) \u2192 &#8216;good number&#8217;<\/li>\n<li>19 (1 + 9 = 10) \u2192 &#8216;good number&#8217;<\/li>\n<li>18 (1 + 8 = 9) \u2192 &#8216;good number&#8217;<\/li>\n<li>17 (1 + 7 = 8) \u2192 &#8216;good number&#8217;<\/li>\n<li>16 (1 + 6 = 7) \u2192 &#8216;good number&#8217;<\/li>\n<li>15 (1 + 5 = 6) \u2192 &#8216;good number&#8217;<\/li>\n<li>14 (1 + 4 = 5) \u2192 &#8216;good number&#8217;<\/li>\n<li>13 (1 + 3 = 4) \u2192 &#8216;good number&#8217;<\/li>\n<li>12 (1 + 2 = 3) \u2192 &#8216;good number&#8217;<\/li>\n<li>11 (1 + 1 = 2) \u2192 &#8216;good number&#8217;<\/li>\n<li>10 (1 + 0 = 1) \u2192 &#8216;good number&#8217;<\/li>\n<li>9 (9 = 9) \u2192 &#8216;good number&#8217;<\/li>\n<\/ul>\n<p>The largest &#8216;good number&#8217; is 22.<\/p>\n<h2>Approach to Solve the Problem<\/h2>\n<p>\n        To solve this problem, we first calculate the sum of the digits for each number starting from N-1 going downwards.<br \/>\n        If the sum of the digits is less than N, we return that number as the result and terminate the algorithm.\n    <\/p>\n<h2>Algorithm Implementation<\/h2>\n<pre>\n        <code>\n        public class GoodNumber {\n            public static void main(String[] args) {\n                int N = 23; \/\/ Set the value of N to test here.\n                int result = findGoodNumber(N);\n                System.out.println(\"The 'good number' is: \" + result);\n            }\n\n            public static int findGoodNumber(int N) {\n                for (int i = N - 1; i &gt; 0; i--) {\n                    if (digitSum(i) &lt; N) {\n                        return i; \/\/ Return the largest 'good number'\n                    }\n                }\n                return -1; \/\/ Return -1 if not found\n            }\n\n            public static int digitSum(int num) {\n                int sum = 0;\n                while (num &gt; 0) {\n                    sum += num % 10; \/\/ Add each digit\n                    num \/= 10; \/\/ Divide by 10 to reduce the number of digits\n                }\n                return sum;\n            }\n        }\n        <\/code>\n        <\/pre>\n<h2>Code Explanation<\/h2>\n<p>\n        In the Java code above, the main method sets the value of N, then calls the <code>findGoodNumber<\/code> method to find the &#8216;good number&#8217;.<br \/>\n        The <code>findGoodNumber<\/code> method starts from N-1 and calculates the sum of the digits, returning the number if that value is less than N.\n    <\/p>\n<p>\n<code>digitSum<\/code> method contains the logic to calculate the sum of each digit of the given number.<br \/>\n        This method uses a loop to separate the digits one by one and returns the summed result.\n    <\/p>\n<h2>Time Complexity Analysis<\/h2>\n<p>\n        The time complexity of this algorithm is O(N * D), where N is the input value and D is the number of digits in N.<br \/>\n        It requires O(D) operations to sum the digits for each number, resulting in a worst-case time complexity of O(N * D).\n    <\/p>\n<h2>Space Complexity<\/h2>\n<p>\n        The space complexity is O(1). It does not use additional space, and only the input\/output variables and constant space within methods are used,<br \/>\n        thus minimizing the memory used.\n    <\/p>\n<h2>Conclusion and Tips<\/h2>\n<p>\n        The problem of finding a &#8216;good number&#8217; can be easily solved through a simple loop and digit sum process.<br \/>\n        However, if N is very large, performance degradation may be a concern, so algorithm optimization may be necessary.<br \/>\n        Testing this problem with various input values and attempting to solve it with different methods or structures can be a good learning experience.\n    <\/p>\n<p>\n        Finally, it is important to practice these types of problems thoroughly while preparing for coding tests.<br \/>\n        Facing new problems every time and cultivating diverse thinking skills will greatly assist in job preparation.\n    <\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description Given a number N, write a computer program that can transform N such that the sum of its digits is less than N. Here, a number where the sum of its digits is less than N is called a &#8220;good number&#8221;. In other words, this is an algorithm problem to find the largest &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33295\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, &#8216;Finding Good Numbers&#8217;&#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-33295","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, &#039;Finding Good Numbers&#039; - \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\/33295\/\" \/>\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, &#039;Finding Good Numbers&#039; - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Problem Description Given a number N, write a computer program that can transform N such that the sum of its digits is less than N. Here, a number where the sum of its digits is less than N is called a &#8220;good number&#8221;. In other words, this is an algorithm problem to find the largest &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, &#8216;Finding Good Numbers&#8217;&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33295\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:15:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:39:18+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\/33295\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33295\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, &#8216;Finding Good Numbers&#8217;\",\"datePublished\":\"2024-11-01T09:15:16+00:00\",\"dateModified\":\"2024-11-01T11:39:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33295\/\"},\"wordCount\":421,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33295\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33295\/\",\"name\":\"Java Coding Test Course, 'Finding Good Numbers' - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:15:16+00:00\",\"dateModified\":\"2024-11-01T11:39:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33295\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33295\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33295\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, &#8216;Finding Good Numbers&#8217;\"}]},{\"@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 Good Numbers' - \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\/33295\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, 'Finding Good Numbers' - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Problem Description Given a number N, write a computer program that can transform N such that the sum of its digits is less than N. Here, a number where the sum of its digits is less than N is called a &#8220;good number&#8221;. In other words, this is an algorithm problem to find the largest &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, &#8216;Finding Good Numbers&#8217;\"","og_url":"https:\/\/atmokpo.com\/w\/33295\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:15:16+00:00","article_modified_time":"2024-11-01T11:39:18+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\/33295\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33295\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, &#8216;Finding Good Numbers&#8217;","datePublished":"2024-11-01T09:15:16+00:00","dateModified":"2024-11-01T11:39:18+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33295\/"},"wordCount":421,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33295\/","url":"https:\/\/atmokpo.com\/w\/33295\/","name":"Java Coding Test Course, 'Finding Good Numbers' - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:15:16+00:00","dateModified":"2024-11-01T11:39:18+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33295\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33295\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33295\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, &#8216;Finding Good Numbers&#8217;"}]},{"@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\/33295","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=33295"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33295\/revisions"}],"predecessor-version":[{"id":33296,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33295\/revisions\/33296"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}