techgig.com-triangle max sum
DESCRIPTION
java challangesTRANSCRIPT
techgig.comhttp://www.techgig.com/assessment/question/MjgxNUAjJEAjJDE1ODU2ODBAIyRAIyQyMjA5NTc1QCMkQCMkMTQ0OTU2NjcwNg==/1
Triangle Max Sum
Download App
Time Remaining 2:23:19
Imagine you have a row of numbers like below(a triangle). By starting at the top of the triangle, find the maximumnumber in each line and sum them up. Example below.
59 64 6 80 7 1 5
Answer I.e. 5 + 9 +8 + 7 = 29.
Write a code to find the maximum total from top to bottom. Assume triangle can have at most 100000 rows.
Input/Output Specifications Input Specification:A string of n numbers (where 0<=n<=1010)
eg. 5#9#6#4#6#8#0#7#1#5
Output Specification:
A sum of the max numbers in each line(as string) Or Output Invalid in case of Invalid input/triangle.
Exampleseg1:
Input: 5#9#6#4#6#8#0#7#1#5
Output: 29
eg2:
Input: 5#9#6#4#6#8#0#7#1
Output: Invalid
eg2:
Input: 5#9##4#6#8#0#7#1
Output: Invalid
Instructions:
1) Do not write main function.
2) You can print and debug your code at any step of the code.
3) You need to return the required output from the given function.
4) Do not change the function and parameter names given in editor code.
5) Return type must be the same as mentioned in the problem statement.
6) When you submit your code, 10 test cases of different complexity level are executed in the background and marksare given based on number of test cases passed.
7) If you do not plan to complete the code in one sitting, then please save your work on a local machine. The code issaved only when it has been submitted using Submit button.
8 ) Only two submissions are allowed.
See sample problems & answers