Nokia 2
Nokia 2
NO<IA
02:18:08:14
DAY HRS MIN SEC
Accelerate Her in Tech - A Student Hackathon (Round 2)
LIVE INVITE ONLY ACCESS
Mar 21, 2025, 12:00 AM IST (Asia/Kolkata) - Mar 23, 2025, 11:59 PM IST (Asia/Kolkata)
Math challenge
Max, score: 100
Bob's dad, a sneaky mathematician, hands him a list of numbers and a challenge. He asks him to pick any two numbers, subtract one from the
other, replace the first number with the result, and throw the second number away. Bob must keep going until only one number is left.
Whatever that number is, he wins that much money!
Bob, dreaming of riches, is all in—until he realizes something horrifying. If he messes up, the final number could be zero or even negative.
Which means he'd have to pay his dad instead! Now, it's not just about making money but not going broke. Help Bob play his moves wisely
and maximize his final reward (or at least avoid financial ruin)!
Task
Return the maximum possible value of the last remaining element after performing the operations optimally.
Function description
Complete the function solve() provided in the editor. This function takes the following two parameters and returns the required answer:
* N: Represents the number of elements in the array.
* nums: A list of Nintegers.
Input format
Note: This is the input format you must use to provide custom input (available above the Compile and Test button).
« The first line contains a single integer N (size of the array).
« The second line contains N space-separated integers representing the array nums.
Output format
For each test case, print the required answer on a new line.
Constraints
+ 2<N<5x10°
+ —10° < numsli] < 10°
SAMPLE INPUT S A
4
724 -2
SAMPLE OUTPUT % 7
15
Explanation
Given
7242
Approach
Bob wants to maximize his reward. Here's one possible sequence of operations:
1. Choose
2. Choose i=
3. Choose
4. Choose =2 — A=[15]
74
542692413 431289040 751517587 36263053 153653087 473978623 359295400 498538404 249407871 125490925 326410002
68444699 915685133 312134485 158237048 310587142 301859367 670843317 715111823 949340977 -756468392 658898446
384961553 292823350 -13044556 228396630 988225135 934848973 228730979 504556161 827421405 255009564 770780264
221633515 935058705 453798416 997428023 563526172 16266152 887191607 777403006 991110236 832054890 888790760
247795414 708830345 536852241 958815158 950105212 91312661 373043854 163574484 217474524 -157855783 83107236
491983564 812575164 288877309 -779466209 974730139 452798806 644540211 615845063 414682629 -495690378 706991250
-115979072 257012690 158598420 552758541 802051495 823058099 89895444 210471808
SAMPLE OUTPUT #1 % A
36935980483
SAMPLE INPUT #2 % @
61893
180612787 -899002964 168435580 -956880872 -897449403 277068725 233796595 364202975 -10691006 339067980 389479895
900041451 251857230 990226456 998800297 960862833 951219963 318791558 463091922 521090111 651117771 -88140604
930085476 545597751 295584122 762661656 74602480 90085053 647344704 292527150 264455505 381550193 459136997 59282584
80832558 693543163 199340819 760352008 209007688 736207167 255506372 575230520 274890407 875212599 516768016
727911719 332706909 278633208 627344710 -240324474 582363810 990901118 9864825 326368135 406395561 -28435222
680807668 241342324 482858317 329970089 102951052 724906096 589760529 906315062 650908953 257555115 217066281
-502923989 303294393 611689619 -76590068 -203129180 464105734 96981674 628207066 764405435 938052969 857816920
222327668 236078821 3740439 308985028 714555447 630005477 303646739 830489605 579533881 732676395 322377675 86044340
674065354 663369952 -146647201 6022262 815914012 836468365 14750247 268300172 648596414 -256016786 9572343
1:1 vscode
Test against custom input ¥ Compile & Test code Submit code
A Warning: Copy & Paste in code editor is not allowed for this challenge. If you think this is an issue, please contact administrator at [email protected].
# Tip: You can submit any number of times you want. Your best submission is considered for computing total score.
& Support: For any queries or issues, write to [email protected].