CT28767

The Runner-Up Beneath Petalbrook

EasyL3 · Syntax SurferAcceptance: 0.0%XP: 20

At the garden city of Petalbrook, Odin records each crates in a worn leather ledger. The guild wants answers, not guesses. Task: Read n integers and print the second distinct largest value. If every value is the same, print -1. Input format: First line: n. Second line: n space-separated integers. Output format: Print the second distinct maximum, or -1 if none. Constraints: 1 <= n <= 638; -1000000 <= a[i] <= 1000000000; answers fit a signed 64-bit integer.

Example 1:

Input: 577 991088006 911351271 804645007 197697950 112507399 511545113 247401017 324092565 60489417 999415535 403375812 752106097 657071599 985183273 412308408 679661486 659307017 365668988 999611497 56248551 274019206 916660472 989729394 112787912 719247758 794780552 215369882 195911089 379146880 954481506 845802034 804377839 503109688 427030478 496071489 370833214 443503634 471876746 333983130 990121223 658078689 151920160 251750957 286506900 556995314 28847138 117366714 728839638 631201037 690568446 323244797 356886140 647302999 554241444 159808644 379578051 797773863 247678767 859821484 280047682 298540692 236345209 806766608 574589300 15857761 190376832 558261668 814030042 664806868 531371278 238248494 336565966 762737392 307814972 927456117 789278506 347300532 848545166 975060897 250502678 …
Output: 999415535

Example 2:

Input: 369 68389218 105797671 913119862 685964293 897846672 253987535 220313917 787758735 7928660 41443148 931515823 658928678 925540274 169894018 43593895 508440703 881638773 415518899 158500038 850494334 473504364 343142944 983091993 791903161 432815993 817169388 308472438 944543134 276364799 382447393 899456871 206813657 260404293 308641235 76840397 966236577 168481147 67979269 501202427 613955255 383787761 576149218 295363645 589957449 199086795 919753321 317797854 35709620 392552955 764736592 127111085 391935947 497985766 687233172 190893982 623084531 588774223 462880182 728044874 979850753 892813228 998106388 430369312 675297702 746564961 586541977 795257475 262576420 572359278 415885870 980788004 726732982 930400970 704869280 687582000 842072124 330686370 972645780 882819464 298383938 6628…
Output: 998106388

Example 3:

Input: 338 196984008 110892377 944758696 236547504 327868259 196878556 692169302 249880686 288840897 38248236 193351879 329450304 511729743 412633788 735865843 118684311 945139955 50062712 458397511 166886384 154821635 210311578 419334010 168909551 677214605 307754957 765449651 988709774 11383391 64360003 145890958 755294289 306052612 8543554 33015777 472304572 898582713 126796035 374830889 561792746 344756077 742940235 888850937 152733394 381881880 351140519 361551461 273565656 584899597 115921266 519598528 841973015 941025759 495871487 950005326 354416664 218446957 597633066 880325130 272744015 260315582 669472989 364985026 682676792 487186553 973274623 905081445 890451568 589389256 477101835 30497721 431235365 141534527 132343909 71861432 189839744 197909666 85335990 783816384 418701255 222888…
Output: 994917380

Constraints:

1 <= n <= 638; -1000000 <= a[i] <= 1000000000; answers fit a signed 64-bit integer.

Loading...
Test Cases:No test cases
No test cases available.
The Runner-Up Beneath Petalbrook - EASY Coding Problem | CodeTikki