Question:
How to solve maximum sum problem using Python3

Summary

Let’s assume that:

Class: Solution

Method: maxSum


Solution

#User function Template for python3


class Solution:

    def maxSum(self, n): 

        # code here

        a,b,c=n//2,n//3,n//4

        if a+b+c>n:

            z=self.maxSum(a)+self.maxSum(b)+self.maxSum(c)

            return z

        else:

            return n


Explanation

  • class Solution:: This defines the Solution class.

  • def maxSum(self, n):: This defines the Solution class's maxSum method, which accepts an integer n as input.

  • n//2, n//3, n//4=a, b, and c: divides the input number n into three variables, a, b, and c, which, in turn, represent roughly half, third, and fourth of n, respectively.

  • If a+b+c>n, it means that a, b, and c added together are greater than n.


Answered by:> >swarup2karmakar

Credit:> >GeekforGeeks


Suggested blogs:

>How to configure python in jmeter?

>How to mock a constant value in Python?

>Creating a pivot table by 6 month interval rather than year

>How to Install mariaDB client efficiently inside docker?

>Can I call an API to find out the random seed in Python `hash()` function?

>How remove residual lines after merge two regions using Geopandas in python?


Submit
0 Answers