CT29336

Rosa's Starlit shelves

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Rosa found an old ledger of shelves in the archive attic at the otter slides of Sleekwater. The margin notes pose a precise question. 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 <= 6681; 0 <= a[i],x <= 1000.

Example 1:

Input: 546 119 0 2 4 7 7 11 17 19 20 20 23 23 25 25 25 26 30 30 31 36 39 43 45 46 50 51 52 53 55 58 58 59 62 63 66 68 69 70 70 71 72 74 74 76 79 80 84 86 88 88 89 92 92 93 94 98 105 108 110 113 115 116 121 121 122 126 128 130 132 132 132 132 134 135 135 136 136 137 145 147 147 148 150 151 157 160 162 162 163 163 164 165 166 170 172 173 174 174 175 175 180 181 181 187 191 191 191 195 197 199 200 201 204 204 204 205 207 207 212 218 219 219 224 226 227 227 227 231 232 239 242 243 243 244 244 245 246 253 254 257 266 268 271 277 278 281 283 284 284 287 287 292 292 299 299 301 302 303 306 307 308 309 312 314 319 320 320 322 322 326 329 329 330 331 334 335 337 348 349 351 353 353 354 355 356 356 356 356 361 362 364 366 367 368 368 369 376 377 380 380 381 382 382 383 383 383 385 387 388 388 389 389 390 3…
Output: -1

Example 2:

Input: 308 109 4 7 7 10 11 12 22 23 32 32 33 34 35 39 40 47 48 55 55 56 61 64 69 69 70 71 72 76 76 79 83 87 89 92 95 96 100 101 106 116 118 118 119 122 122 140 150 150 151 151 163 165 166 166 167 182 183 185 185 189 190 194 196 197 200 208 212 219 219 224 229 232 236 236 239 240 242 244 248 251 252 254 255 265 268 273 273 277 277 278 279 280 282 282 283 284 285 286 289 292 294 299 300 305 307 308 309 317 322 331 339 343 347 352 355 357 359 360 360 360 361 364 364 369 370 375 383 384 385 386 386 388 390 398 399 406 407 409 410 412 414 418 421 429 429 430 432 434 436 436 439 440 441 444 446 451 453 456 458 462 466 472 477 478 483 483 487 488 490 505 511 516 520 524 524 532 537 539 542 547 551 551 564 565 568 573 575 585 586 588 605 605 610 613 614 619 630 636 637 647 648 655 657 657 658 660 663 663…
Output: -1

Example 3:

Input: 5828 378 0 0 0 0 0 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 10 10 10 10 10 10 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 14 14 14 14 14 15 15 15 15 15 16 16 16 16 16 18 18 18 18 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 21 21 21 21 21 21 22 22 22 22 22 22 23 23 23 23 23 24 24 24 24 24 25 25 25 25 25 26 26 26 26 26 26 26 26 26 26 26 27 27 27 27 27 27 28 28 28 28 28 29 29 29 29 29 30 30 30 30 31 31 31 31 32 32 32 33 33 33 33 34 34 34 34 34 34 35 35 35 36 36 36 36 36 36 37 37 37 38 38 38 38 38 39 39 39 39 39 39 39 39 39 39 40 40 40 40 41 41 41 42 42 42 42 42 43 43 43 43 43 43 44 44 44 44 44 44 44 45 45 45 45 45 45 45 45 45 45 46 46 46 46 46 46 47 47 47 48 48 48 48 48 48 49 49 49 50 50 50 50 50 5…
Output: 2243

Constraints:

1 <= n <= 6681; 0 <= a[i],x <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Rosa's Starlit shelves - MEDIUM Coding Problem | CodeTikki