CT32496

Kian Counts the shelves

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

In the anvil district of Hammerfall, Kian the clerk keeps careful count of the shelves. Plan the festival budget, every figure matters. 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 <= 7013; 0 <= a[i],x <= 1000000.

Example 1:

Input: 6594 115533 61 77 503 552 555 764 823 1007 1144 1161 1320 1360 1403 2104 2648 2668 2803 3024 3027 3632 3830 4176 4243 4266 4352 4419 4978 5061 5220 5288 5653 5860 5970 6202 6337 6434 6690 6726 7205 7419 7583 7682 7818 7868 7918 8021 8038 8145 8188 8449 8452 8517 8535 8548 8577 8599 8655 8657 8674 8733 8896 9498 9565 9804 10186 10341 10454 10647 10688 10720 10935 11374 11375 11747 11771 11851 11932 12508 12656 12771 13015 13260 13804 14051 14133 14324 14347 14431 14577 14930 15105 15788 16243 16544 16641 16791 16821 16893 16957 16980 17313 17321 17389 17421 17823 17898 17914 18202 18361 18382 18542 18610 18679 18850 19039 19097 19099 19500 19564 19801 20249 20296 20444 20461 20509 20513 20720 20746 20876 21222 21547 21831 21880 21902 21913 22045 22085 22319 22329 22348 22390 22525 22581 229…
Output: -1

Example 2:

Input: 5835 668536 22 740 882 1089 1178 1272 1351 1697 2030 2254 2272 2367 2475 2783 2791 2811 3014 3405 3442 3899 3919 3945 4569 4607 4616 4847 5188 5489 5501 5708 5711 6174 6432 6442 6518 6599 6618 6744 6767 7051 7182 7307 7308 7620 8001 8105 8715 9021 9029 9267 9442 9692 9751 9887 9909 10024 10055 10326 10414 10903 11170 11491 11879 11887 12061 12169 12186 12289 12327 12547 12574 12853 12864 12989 13051 13431 13856 14027 14094 14176 14456 14641 15266 15272 15347 15833 16028 16067 16178 16342 16365 16464 16494 16544 16698 16916 16983 16990 17184 17268 17280 17393 17519 17649 17666 17968 18003 18191 18294 18432 18493 19134 19262 19347 19510 19877 20356 20473 20635 20784 20813 20856 21010 21023 21182 21686 22045 22115 22479 22685 23050 23100 23493 23674 23709 23804 24136 24603 25088 25115 25600 2…
Output: -1

Example 3:

Input: 676 13023 3593 6005 6126 6647 12319 12381 13023 13995 14243 14774 15949 16505 17788 18233 24465 25027 26767 28038 29147 29266 29331 29441 33733 33884 35454 35834 37524 37889 39405 39562 41361 43014 46021 46125 46577 46782 46992 47844 48704 49253 50212 59618 60680 63165 64735 65963 67944 68875 69399 69475 69520 70948 73339 73777 75281 77984 80283 80296 80465 80666 81325 85105 85694 87640 90619 92028 93009 93680 95435 95570 95887 95892 100234 101161 101162 101559 103867 104040 106377 107085 109525 112406 113318 113676 114848 116340 118709 120245 121933 122515 123712 125627 126919 128183 129062 130086 130992 131179 131840 135011 136172 137035 137523 138232 140773 147521 148673 148782 150318 150590 151748 152556 152623 153200 155577 156759 159498 161348 161592 164794 166224 167883 174594 17483…
Output: 7

Constraints:

1 <= n <= 7013; 0 <= a[i],x <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Kian Counts the shelves - MEDIUM Coding Problem | CodeTikki