{"id":13649,"date":"2021-09-30T16:30:01","date_gmt":"2021-09-30T11:00:01","guid":{"rendered":"https:\/\/python-programs.com\/?p=13649"},"modified":"2021-11-22T18:34:24","modified_gmt":"2021-11-22T13:04:24","slug":"python-program-to-find-maximum-product-quadruple-in-an-array-or-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-maximum-product-quadruple-in-an-array-or-list\/","title":{"rendered":"Python Program to find Maximum Product Quadruple in an Array or List"},"content":{"rendered":"
Are you a job seeker and trying to find simple java programs for Interview?<\/a> This would be the right choice for you, just tap on the link and start preparing the java programs covered to crack the interview.<\/p>\n Given a list, the task is to write a python program to find the Maximum Product Quadruple in the given array or list in Python.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to find the Maximum Product Quadruple in the given array or list in Python.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Time complexity:<\/strong> O(n*logn) where n is the length of the given list.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Time complexity:<\/strong> O(n*logn) where n is the length of the given list. Are you a job seeker and trying to find simple java programs for Interview? This would be the right choice for you, just tap on the link and start preparing the java programs covered to crack the interview. Given a list, the task is to write a python program to find the Maximum Product Quadruple …<\/p>\nGiven list =[-9, -24, 15, 3, 19, 23, 18, 11, 10, 7, 6]<\/pre>\n
The maximum product quadruple in the given list [-9, -24, 15, 3, 19, 23, 18, 11, 10, 7, 6] is :\r\n[ 117990 ]<\/pre>\n
Given list =[8, 11, 4, 6, 9, -7, 22, 9, 15]<\/pre>\n
The maximum product quadruple in the given list [8, 11, 4, 6, 9, -7, 22, 9, 15] is :\r\n[ 32670 ]<\/pre>\n
Program to find Maximum Product Quadruple in an Array or List in Python<\/h2>\n
\n
Method #1: Using Sorting (Static Input)<\/h3>\n
\n
# Give the list as static input and store it in a variable.\r\ngvnlist = [-9, -24, 15, 3, 19, 23, 18, 11, 10, 7, 6]\r\nprint('The maximum product quadruple in the given list', gvnlist, 'is :')\r\n# Sort the given list in ascending order using the built-in sort() function.\r\ngvnlist.sort()\r\n# Find the product of the last four elements in the above-sorted list\r\n# and store it in a variable maxproduct1.\r\nmaxproduct1 = gvnlist[-1]*gvnlist[-2]*gvnlist[-3]*gvnlist[-4]\r\n# Find the product of the first four elements in the above-sorted list\r\n# and store it in a variable\r\nmaxproduct2 = gvnlist[0]*gvnlist[1]*gvnlist[2]*gvnlist[3]\r\n# Find the product of the first two elements and last two elements\r\n# in the above-sorted list and store it in a variable maxproduct3.\r\nmaxproduct3 = gvnlist[0]*gvnlist[1]*gvnlist[-1]*gvnlist[-2]\r\n# Find the maximum value of the above three variables\r\n# maxproduct1,maxproduct2,maxproduct3 using the max() function.\r\nmaxproductval = max(maxproduct1, maxproduct2, maxproduct3)\r\n# Print the maximum product.\r\nprint('[', maxproductval, ']')\r\n<\/pre>\n
The maximum product quadruple in the given list [-9, -24, 15, 3, 19, 23, 18, 11, 10, 7, 6] is :\r\n[ 117990 ]<\/pre>\n
Method #2: Using Sorting (User Input)<\/h3>\n
\n
# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvnlist = list(map(int, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\nprint('The maximum product quadruple in the given list', gvnlist, 'is :')\r\n# Sort the given list in ascending order using the built-in sort() function.\r\ngvnlist.sort()\r\n# Find the product of the last four elements in the above-sorted list\r\n# and store it in a variable maxproduct1.\r\nmaxproduct1 = gvnlist[-1]*gvnlist[-2]*gvnlist[-3]*gvnlist[-4]\r\n# Find the product of the first four elements in the above-sorted list\r\n# and store it in a variable\r\nmaxproduct2 = gvnlist[0]*gvnlist[1]*gvnlist[2]*gvnlist[3]\r\n# Find the product of the first two elements and last two elements\r\n# in the above-sorted list and store it in a variable maxproduct3.\r\nmaxproduct3 = gvnlist[0]*gvnlist[1]*gvnlist[-1]*gvnlist[-2]\r\n# Find the maximum value of the above three variables\r\n# maxproduct1,maxproduct2,maxproduct3 using the max() function.\r\nmaxproductval = max(maxproduct1, maxproduct2, maxproduct3)\r\n# Print the maximum product.\r\nprint('[', maxproductval, ']')\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 8 11 4 6 9 -7 22 9 15\r\nThe maximum product quadruple in the given list [8, 11, 4, 6, 9, -7, 22, 9, 15] is :\r\n[ 32670 ]<\/pre>\n
\nRelated Programs<\/strong>:<\/p>\n\n