Given the sum of length, breadth and height of a cuboid. The task is to find the maximum volume that can be achieved such that the sum of sides is S.
 
Example 1:
Input:
S = 8
Output:
18
Explanation:
All possible edge dimensions:
[1, 1, 6], volume = 6
[1, 2, 5], volume = 10
[1, 3, 4], volume = 12
[2, 2, 4], volume = 16
[2, 3, 3], volume = 18
So, Maximum possible Volume is 18.
Example 2:
Input:
S = 6
Output:
8
Explanation:
All possible edge dimensions:
[1, 1, 4], volume = 4
[1, 2, 3], volume = 6
[2, 2, 2], volume = 8
So, Maximum possible Volume is 8.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function maximizeVolume() which takes an Integer S as input and returns the answer.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
3 <= S <= 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def maximizeVolume(self, S):

        # code here 

Solutions:
class Solution:

	def maximizeVolume(self, S):
		l = S // 3
		S = S - l
		b = S // 2
		h = S - b
		return l * b * h


class Solution:

	def maximizeVolume(self, S):
		if S % 3 == 0:
			return S // 3 * (S // 3) * (S // 3)
		elif S % 3 == 1:
			return S // 3 * (S // 3) * (S // 3 + 1)
		else:
			return S // 3 * (S // 3 + 1) * (S // 3 + 1)


class Solution:

	def maximizeVolume(self, S):
		k = S // 3
		if S % 3 == 0:
			return k ** 3
		else:
			k = round(S / 3)
			return k * k * (S - 2 * k)


class Solution:

	def maximizeVolume(self, s):
		if s % 3 == 0:
			return (s // 3) ** 3
		elif s % 3 == 1:
			a = s // 3
			b = a + 1
			return a * a * b
		else:
			a = s // 3
			b = a + 1
			return a * b * b


class Solution:

	def maximizeVolume(self, S):
		a = S // 3
		b = (S - a) // 2
		c = S - a - b
		return a * b * c


class Solution:

	def maximizeVolume(self, S):
		l = b = h = S // 3
		r = S % 3
		if r == 2:
			l += 1
			b += 1
		elif r == 1:
			l += 1
		ans = l * b * h
		return ans


class Solution:

	def maximizeVolume(self, S):
		if S % 3 == 0:
			l = S // 3
			b = S // 3
			h = S // 3
			return l * b * h
		if S % 3 == 1:
			l = S // 3 + 1
			b = S // 3
			h = S // 3
			return l * b * h
		l = S // 3 + 1
		b = S // 3 + 1
		h = S // 3
		return l * b * h