CT28472

Gardener's lanterns Reckoning

EasyL3 · Syntax SurferAcceptance: 0.0%XP: 20

Caravans arrive at the trading post of Goldmeadow with crates of lanterns, and Gardener the store warden must account for every last one. Task: Read n integers and print the first value that appears twice (the value whose second occurrence has the smallest index). If all are distinct print -1. Input format: First line: n. Second line: n space-separated integers. Output format: Print the first repeated value, or -1. Constraints: 1 <= n <= 278; -1000000 <= a[i] <= 10; answers fit a signed 64-bit integer.

Example 1:

Input: 65 -798513 -560361 -855905 -615436 -953923 -392508 -292171 -495749 -400645 -784172 -217584 -660799 -745011 -365989 -968263 -82907 -798008 -341663 -134857 -611210 -952499 -21044 -121009 -749770 -525218 -578413 -460959 -367452 -786641 -622630 -720226 -251183 -708012 -865207 -307962 -870953 -547428 -192684 -485140 -398950 -70177 -70912 -514138 -773409 -620841 -898961 -580729 -52706 -612865 -239789 -412992 -728650 -139785 -479807 -97893 -474176 -391765 -712956 -593749 -355941 -578413 -945670 -956452 -526871 -62345
Output: -578413

Example 2:

Input: 237 -75426 -564822 -204956 -793236 -126786 -724129 -142635 -117333 -770307 -123046 -758785 -931396 -761711 -276512 -99457 -183474 -69457 -285703 -633688 -801235 -221719 -360995 -603716 -659334 -744900 -913989 -956663 -680012 -538365 -811223 -691666 -988114 -480665 -403334 -776410 -265985 -27949 -436620 -602166 -893914 -255971 -496309 -588093 -982796 -953516 -639149 -686668 -582715 -387680 -890822 -103793 -27858 -663696 -678341 -594036 -215594 -651300 -730185 -86671 -337303 -333471 -229062 -932166 -243723 -861972 -641641 -456245 -636757 -105805 -969291 -419272 -788009 -906494 -967287 -24941 -337897 -439161 -536984 -106684 -801033 -147252 -419005 -335303 -158906 -648377 -116395 -970225 -312251 -512621 -361643 -944355 -774391 -582825 -37053 -598755 -538462 -636903 -47368 -992518 -980812 -1850…
Output: -1

Example 3:

Input: 241 -958090 -260941 -674962 -579611 -130449 -434394 -354423 -912536 -260785 -661170 -108405 -475121 -191440 -406682 -451227 -194936 -776885 -975668 -1141 -495116 -553746 -927717 -553358 -510926 -934698 -540396 -157256 -190408 -940465 -243471 -845909 -828258 -584984 -689704 -452138 -557559 -907424 -680143 -550891 -373674 -711908 -406217 -628710 -223978 -529401 -483291 -485663 -972932 -687733 -391557 -498278 -903675 -679943 -928904 -19689 -190155 -102587 -838135 -546644 -253477 -462574 -214660 -134867 -454029 -242324 -321317 -20579 -538390 -28863 -980515 -32644 -200281 -961418 -979609 -426198 -133834 -200949 -412946 -553409 -321185 -70239 -438394 -57922 -828672 -765795 -783954 -503902 -779254 -561320 -948196 -542551 -737417 -384847 -105941 -322323 -184095 -651649 -395495 -903783 -318581 -694…
Output: -452138

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.