{"id":4723,"date":"2022-12-05T09:38:55","date_gmt":"2022-12-05T09:38:55","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=4723"},"modified":"2022-12-05T12:06:11","modified_gmt":"2022-12-05T12:06:11","slug":"code-challenges-1","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/code-challenges-1\/","title":{"rendered":"Code Challenges 1"},"content":{"rendered":"<p><strong class=\"ctaHeader2\">Find the Minimum and Maximum Sum<\/strong><\/p>\n<p><strong>Input Format<\/strong><br \/>\nA single line of five space-separated integers.<\/p>\n<p><strong>Constraints<\/strong><\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 22px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/codethataint.com\/blog\/wp-content\/ql-cache\/quicklatex.com-83c987b36d9aa35ebe4b8959adb7e0d7_l3.png\" height=\"22\" width=\"122\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#49;&#60;&#97;&#114;&#114;&#91;&#105;&#93;&#60;&#49;&#48;&#94;&#57;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p><strong>Output Format<\/strong><br \/>\nPrint two space-separated long integers denoting the respective minimum and maximum values.<\/p>\n<p><strong>Sample Input<\/strong><\/p>\n<pre>\r\n1 2 3 4 5\r\n<\/pre>\n<p><strong>Sample Output<\/strong><\/p>\n<pre>\r\n10 14\r\n<\/pre>\n<ol>\n<li>Find the Minimum and Maximum Element in array<\/li>\n<li>When you calculate the minSum and maxSum &#8211; discard the maxElement and minElement<\/li>\n<li>Trick is you may miss logic if the array contains 5 elements and all are of same value. In such case the maximum and minimum value elements are same<\/li>\n<li>For finding minimum number, start by assigning maximum number to minNum<\/li>\n<\/ol>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n.\r\n.\r\n public static void miniMaxSum(List&lt;Integer&gt; arr) {\r\n        long minNum = 0;\r\n        long maxNum = 0;\r\n\r\n        long minSum = 0;\r\n        long maxSum = 0;\r\n\r\n\r\n        \/\/To find maximum Number\r\n        for(int num=0;num&lt;arr.size();num++){\r\n            if(maxNum&lt;=arr.get(num)){\r\n                maxNum = arr.get(num);\r\n            }\r\n        }\r\n\r\n        \/\/To find minimum Number\r\n        minNum = maxNum;\r\n\r\n        for(int num=0;num&lt;arr.size();num++){\r\n            if(arr.get(num)&lt;=minNum){\r\n                minNum = arr.get(num);\r\n            }\r\n        }\r\n\r\n        for(int num=0;num&lt;arr.size();num++){\r\n            \/\/If the array elements are of same value\r\n            if(num!=0 &amp;&amp; arr.get(num) == arr.get(num-1)){\r\n                minSum +=arr.get(num);\r\n                maxSum +=arr.get(num);\r\n            }\r\n\r\n\r\n            if(arr.get(num) != maxNum)\r\n              minSum +=arr.get(num);\r\n\r\n            if(arr.get(num) != minNum)\r\n              maxSum +=arr.get(num);\r\n        }\r\n\r\n        System.out.println(minSum);\r\n        System.out.println(maxSum);\r\n    }\r\n.\r\n.\r\n<\/pre>\n<p><strong class=\"ctaHeader2\">Get Count of biggest Element in array &#8211; Total Tallest Candles to be blown<\/strong><\/p>\n<p><strong>Input Format<\/strong><br \/>\nArray of Integers<\/p>\n<p><strong>Constraints<\/strong><\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 22px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/codethataint.com\/blog\/wp-content\/ql-cache\/quicklatex.com-272ea8f947d07ad873b85cc10ac2a88d_l3.png\" height=\"22\" width=\"155\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#49;&#60;&#99;&#97;&#110;&#100;&#108;&#101;&#115;&#91;&#105;&#93;&#60;&#49;&#48;&#94;&#55;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p><strong>Output Format<\/strong><br \/>\nCount of Biggest Element in array<\/p>\n<p><strong>Sample Input<\/strong><\/p>\n<pre>\r\n3 2 1 3 5 6 5 4 5\r\n<\/pre>\n<p><strong>Sample Output<\/strong><\/p>\n<pre>\r\n1\r\n<\/pre>\n<ol>\n<li>In the above example 6 is the biggest element and it occurs only once<\/li>\n<li>Find the biggest element in array<\/li>\n<li>Find the count of the biggest element<\/li>\n<\/ol>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic static int birthdayCakeCandles(List&lt;Integer&gt; candles) {\r\n        \/\/ Write your code here\r\n        long tallestCandle = 0;\r\n        int tallestCandleCnt = 0;\r\n\r\n        for(int num=0;num&lt;candles.size();num++){\r\n            if(tallestCandle&lt;=candles.get(num)){\r\n                tallestCandle = candles.get(num);\r\n            }\r\n        }\r\n\r\n        for(int num=0;num&lt;candles.size();num++){\r\n            if(candles.get(num) == tallestCandle)\r\n                tallestCandleCnt +=1;\r\n        }\r\n\r\n        return tallestCandleCnt;\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Find the Minimum and Maximum Sum Input Format A single line of five space-separated integers. Constraints &nbsp; &nbsp; Output Format Print two space-separated long integers denoting the respective minimum and maximum values. Sample Input 1 2 3 4 5 Sample Output 10 14 Find the Minimum and Maximum Element in array When you calculate the&hellip; <a href=\"https:\/\/codethataint.com\/blog\/code-challenges-1\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[283],"tags":[],"class_list":["post-4723","post","type-post","status-publish","format-standard","hentry","category-code-snippets"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=4723"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4723\/revisions"}],"predecessor-version":[{"id":4740,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4723\/revisions\/4740"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=4723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=4723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=4723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}