CT23255

Sara Counts the crates

EasyL3 · Syntax SurferAcceptance: 0.0%XP: 20

Caravans arrive at the heron rookery of Longlegs with crates of crates, and Sara the paymaster must account for every last one. Task: The array is sorted in non-decreasing order. Print the 1-based index of the first occurrence of x, or -1 if x is absent. Input format: First line: n and x. Second line: n sorted integers. Output format: Print the 1-based index or -1. Constraints: 1 <= n <= 845; -1000000 <= a[i],x <= 1000000000.

Example 1:

Input: 54 773451789 36978 19380133 28803536 35735249 78356403 138689983 160904194 166124819 179722727 191739734 234396695 235638100 236521846 242084164 290084695 355138526 382648299 463896282 501393091 524694336 528673467 548127137 556975601 574712678 584003071 585316145 615276376 623110483 631720417 655291726 661804628 683943477 684379476 697744312 700336047 724611765 746070121 763030285 773451789 798741990 807284766 808600623 828870313 829039531 873391895 906936709 933849417 940902114 960149454 969602314 970522963 982798421 990476254 996938086
Output: 39

Example 2:

Input: 366 274272679 -704298 596717 7956886 11299647 12995268 14293907 14522631 16451413 16844607 20719050 22620578 23375990 23384818 25472898 33942940 37642151 40839646 45036632 47250055 48137508 48895263 49722491 57851806 60017565 60210794 62384822 66819241 72074055 73239986 73763489 75462349 83583575 88549677 89636944 91630068 92682201 95098565 95934940 106384394 107059101 108173656 110742018 112512682 118251899 127701576 129210399 133544957 136641763 137165388 137350416 138549606 144353625 145321014 147354664 148599858 149343633 155989432 157902738 158906269 159839365 164197557 168072138 168525751 169226550 170817729 171895923 171986252 178745419 180362421 181115917 190844433 191455033 195244644 195762652 199113257 199985612 203142242 204419815 207285926 210230810 210741118 218451615 22198018…
Output: 97

Example 3:

Input: 776 805110480 812306 1673912 2212355 2749357 3192217 7012770 8619903 9268051 10065776 11429504 11823470 12826070 13505325 14701856 17654444 17910321 18807180 20331842 22878089 23806073 24286525 24378961 24690472 26774557 27409590 30154463 30488500 30655787 32874814 32980923 36283130 36628141 37765844 42726488 43611425 46295032 47252680 48048027 48364792 48834250 48984308 50533999 54994960 55094288 56192564 56685257 59934281 60867803 61267517 62297869 64914907 65375080 65603799 66755742 68488740 71841785 72844680 75354107 78467021 79214260 80019351 80122307 80463486 80835575 81245307 83357716 84109097 86164186 86340563 87162568 88175566 88447185 89496585 90244831 90870761 93721115 94178827 94944982 95838377 96509590 98013431 98793967 99075508 99549733 101685845 102622557 104965586 105358713…
Output: -1

Constraints:

1 <= n <= 845; -1000000 <= a[i],x <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Sara Counts the crates - EASY Coding Problem | CodeTikki