반응형
Task
- Given three integers a ,b ,c, return the largest number obtained after inserting the following operators and brackets: +, *, ()
- In other words , try every combination of a,b,c with [*+()] , and return the Maximum Obtained
Consider an Example :
With the numbers are 1, 2 and 3 , here are some ways of placing signs and brackets:
- 1 * (2 + 3) = 5
- 1 * 2 * 3 = 6
- 1 + 2 * 3 = 7
- (1 + 2) * 3 = 9
So the maximum value that you can obtain is 9.
Notes
- The numbers are always positive.
- The numbers are in the range (1 ≤ a, b, c ≤ 10).
- You can use the same operation more than once.
- It's not necessary to place all the signs and brackets.
- Repetition in numbers may occur .
- You cannot swap the operands. For instance, in the given example you cannot get expression (1 + 3) * 2 = 8.
Solution:
SELECT GREATEST(((a+b)*c),(a*(b+c)),(a*b*c),(a+b+c))
AS res
FROM expression_matter
The functions to find the maximum and minimum values in parentheses are GREATEST and LEAST, not MAX or MIN.
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Easy SQL: Square Root and Log (0) | 2022.05.17 |
---|---|
Collect Tuition (SQL for Beginners #4) (0) | 2022.05.16 |
SQL Basics: Mod (0) | 2022.05.14 |
Easy SQL: LowerCase (0) | 2022.05.13 |
SQL Basics: Simple WHERE and ORDER BY (0) | 2022.05.12 |