FPEvalDataset/LeetCodeProblem
0304
1{2 "id": 3298,3 "name": "maximize_consecutive_elements_in_an_array_after_modification",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/maximize-consecutive-elements-in-an-array-after-modification/",6 "date": "2024-02-03 00:00:00",7 "task_description": "You are given a **0-indexed** array `nums` consisting of **positive** integers. Initially, you can increase the value of **any** element in the array by **at most** `1`. After that, you need to select **one or more** elements from the final array such that those elements are **consecutive** when sorted in increasing order. For example, the elements `[3, 4, 5]` are consecutive while `[3, 4, 6]` and `[1, 1, 2, 3]` are not. Return _the **maximum** number of elements that you can select_. **Example 1:** ``` **Input:** nums = [2,1,5,1,1] **Output:** 3 **Explanation:** We can increase the elements at indices 0 and 3. The resulting array is nums = [3,1,5,2,1]. We select the elements [**3**,**1**,5,**2**,1] and we sort them to obtain [1,2,3], which are consecutive. It can be shown that we cannot select more than 3 consecutive elements. ``` **Example 2:** ``` **Input:** nums = [1,4,7,10] **Output:** 1 **Explanation:** The maximum consecutive elements that we can select is 1. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 106`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "nums = [2,1,5,1,1]",12 "output": "3 "13 },14 {15 "label": "Example 2",16 "input": "nums = [1,4,7,10]",17 "output": "1 "18 }19 ],20 "private_test_cases": [21 {22 "input": [23 12477224 ],25 "output": 126 },27 {28 "input": [29 1,30 2,31 5,32 6,33 7,34 7,35 8,36 937 ],38 "output": 639 },40 {41 "input": [42 10,43 17,44 31,45 35,46 36,47 41,48 57,49 68,50 68,51 71,52 76,53 78,54 79,55 85,56 9357 ],58 "output": 359 },60 {61 "input": [62 1,63 1,64 2,65 2,66 4,67 5,68 8,69 9,70 10,71 10,72 10,73 11,74 12,75 13,76 14,77 15,78 16,79 17,80 17,81 19,82 20,83 20,84 21,85 21,86 22,87 22,88 22,89 25,90 25,91 27,92 28,93 29,94 29,95 30,96 32,97 32,98 33,99 37,100 39,101 39,102 40,103 40,104 41,105 41,106 42,107 43,108 43,109 44,110 44,111 45,112 48,113 48,114 48,115 49,116 49,117 49,118 51,119 51,120 54,121 55,122 59,123 62,124 66,125 67,126 72,127 72,128 73,129 73,130 75,131 76,132 77,133 77,134 80,135 81,136 81,137 82,138 82,139 84,140 86,141 86,142 87,143 88,144 89,145 89,146 91,147 91,148 92,149 92,150 92,151 93,152 93,153 93,154 93,155 94,156 96,157 97,158 100,159 100,160 101,161 102,162 104,163 105,164 106,165 107,166 110,167 110,168 111,169 112,170 113,171 113,172 113,173 115,174 117,175 118,176 118,177 118,178 118,179 118,180 119,181 125,182 127,183 128,184 129,185 130,186 133,187 134,188 134,189 138,190 139,191 140,192 142,193 145,194 145,195 145,196 151,197 152,198 152,199 157,200 158,201 159,202 159,203 160,204 161,205 162,206 162,207 162,208 163,209 164,210 165,211 166,212 166,213 166,214 167,215 169,216 170,217 170,218 170,219 171,220 174,221 174,222 175,223 175,224 176,225 180,226 182,227 182,228 182,229 186,230 188,231 189,232 191,233 194,234 194,235 194,236 195,237 195,238 197,239 197,240 198,241 203,242 203,243 203,244 206,245 207,246 207,247 207,248 208,249 208,250 208,251 209,252 214,253 215,254 216,255 217,256 217,257 219,258 219,259 220,260 221,261 221,262 223,263 225,264 226,265 227,266 228,267 229,268 230,269 230,270 233,271 233,272 234,273 237,274 238,275 238,276 240,277 242,278 244,279 246,280 246,281 246,282 247,283 248,284 249,285 250,286 251,287 252,288 253,289 253,290 255,291 256,292 259,293 259,294 261,295 261,296 261,297 261,298 262,299 262,300 263,301 264,302 266,303 266,304 268,305 269,306 270,307 271,308 277,309 278,310 279,311 281,312 282,313 283,314 284,315 284,316 285,317 288,318 289,319 290,320 292,321 292,322 293,323 293,324 294,325 296,326 296,327 300,328 300,329 302,330 302,331 303,332 303,333 303,334 304,335 305,336 307,337 307,338 308,339 309,340 310,341 310,342 312,343 312,344 312,345 315,346 316,347 319,348 320,349 320,350 320,351 322,352 323,353 324,354 325,355 326,356 327,357 329,358 330,359 333,360 333,361 334,362 335,363 335,364 335,365 336,366 340,367 341,368 341,369 341,370 341,371 342,372 342,373 343,374 343,375 344,376 344,377 345,378 345,379 346,380 348,381 350,382 353,383 354,384 354,385 355,386 355,387 356,388 356,389 357,390 359,391 359,392 362,393 363,394 364,395 365,396 365,397 365,398 366,399 367,400 367,401 370,402 370,403 372,404 373,405 374,406 374,407 378,408 378,409 380,410 381,411 381,412 383,413 383,414 383,415 385,416 387,417 388,418 389,419 390,420 391,421 392,422 393,423 395,424 395,425 397,426 398,427 398,428 400,429 400,430 401,431 403,432 403,433 403,434 404,435 407,436 407,437 407,438 409,439 409,440 410,441 411,442 411,443 412,444 413,445 414,446 415,447 417,448 417,449 418,450 421,451 422,452 423,453 425,454 430,455 434,456 434,457 435,458 437,459 437,460 439,461 443,462 443,463 444,464 445,465 446,466 446,467 447,468 449,469 451,470 451,471 454,472 456,473 456,474 457,475 457,476 458,477 460,478 462,479 463,480 464,481 464,482 464,483 465,484 465,485 465,486 467,487 467,488 471,489 472,490 472,491 473,492 474,493 475,494 476,495 477,496 477,497 478,498 481,499 482,500 483,501 484,502 485,503 485,504 486,505 487,506 488,507 488,508 488,509 489,510 493,511 494,512 495,513 496,514 496,515 497,516 499,517 499,518 500,519 501,520 501,521 502,522 504,523 506,524 508,525 509,526 512,527 514,528 514,529 520,530 520,531 521,532 522,533 525,534 525,535 526,536 526,537 526,538 528,539 529,540 530,541 530,542 531,543 532,544 532,545 533,546 534,547 535,548 536,549 536,550 537,551 540,552 540,553 540,554 546,555 548,556 548,557 551,558 552,559 553,560 555,561 556,562 558,563 558,564 561,565 562,566 562,567 563,568 563,569 565,570 566,571 566,572 567,573 568,574 569,575 569,576 570,577 571,578 572,579 574,580 577,581 580,582 580,583 581,584 583,585 583,586 585,587 588,588 589,589 589,590 590,591 591,592 592,593 593,594 594,595 595,596 595,597 596,598 596,599 596,600 597,601 599,602 600,603 601,604 602,605 604,606 606,607 610,608 612,609 615,610 615,611 616,612 616,613 617,614 618,615 620,616 621,617 622,618 624,619 624,620 625,621 626,622 626,623 628,624 629,625 630,626 631,627 631,628 632,629 632,630 635,631 636,632 636,633 637,634 637,635 637,636 638,637 639,638 640,639 641,640 642,641 645,642 645,643 647,644 648,645 650,646 651,647 652,648 654,649 655,650 657,651 658,652 658,653 659,654 659,655 660,656 662,657 663,658 664,659 664,660 666,661 666,662 668,663 673,664 678,665 678,666 680,667 680,668 683,669 684,670 686,671 688,672 688,673 688,674 689,675 689,676 693,677 695,678 697,679 699,680 699,681 700,682 701,683 702,684 702,685 703,686 704,687 704,688 705,689 705,690 707,691 708,692 709,693 709,694 710,695 710,696 710,697 712,698 712,699 712,700 712,701 713,702 715,703 715,704 716,705 717,706 718,707 720,708 720,709 721,710 722,711 724,712 725,713 726,714 729,715 731,716 733,717 733,718 734,719 735,720 735,721 735,722 737,723 738,724 741,725 742,726 742,727 742,728 742,729 743,730 744,731 744,732 748,733 748,734 750,735 751,736 751,737 752,738 752,739 754,740 755,741 758,742 760,743 761,744 761,745 761,746 764,747 764,748 764,749 764,750 765,751 769,752 769,753 772,754 773,755 776,756 776,757 778,758 778,759 780,760 780,761 781,762 781,763 783,764 785,765 785,766 787,767 788,768 790,769 790,770 792,771 793,772 793,773 796,774 796,775 799,776 799,777 801,778 803,779 805,780 805,781 806,782 806,783 807,784 808,785 808,786 809,787 809,788 810,789 811,790 814,791 816,792 816,793 819,794 820,795 820,796 821,797 823,798 828,799 830,800 832,801 833,802 834,803 834,804 838,805 838,806 839,807 841,808 841,809 841,810 842,811 843,812 844,813 845,814 846,815 846,816 847,817 851,818 851,819 853,820 854,821 855,822 855,823 856,824 857,825 858,826 859,827 860,828 862,829 862,830 863,831 865,832 867,833 868,834 869,835 870,836 871,837 872,838 872,839 872,840 874,841 876,842 877,843 877,844 883,845 883,846 884,847 886,848 886,849 887,850 890,851 890,852 891,853 891,854 892,855 892,856 892,857 892,858 893,859 895,860 897,861 898,862 898,863 898,864 900,865 901,866 903,867 903,868 904,869 904,870 908,871 908,872 908,873 909,874 909,875 909,876 909,877 910,878 911,879 913,880 913,881 913,882 915,883 915,884 916,885 917,886 917,887 919,888 920,889 921,890 921,891 922,892 923,893 923,894 924,895 929,896 932,897 933,898 939,899 941,900 941,901 944,902 944,903 945,904 946,905 947,906 949,907 949,908 950,909 951,910 952,911 952,912 954,913 954,914 957,915 957,916 959,917 960,918 960,919 960,920 961,921 963,922 964,923 966,924 968,925 969,926 970,927 973,928 975,929 977,930 977,931 977,932 980,933 980,934 980,935 981,936 983,937 984,938 986,939 987,940 987,941 987,942 990,943 990,944 994,945 995,946 997,947 998,948 998,949 999950 ],951 "output": 29952 },953 {954 "input": [955 22,956 42,957 178,958 190,959 195,960 225,961 311,962 338,963 358,964 423,965 516,966 521,967 567,968 572,969 576,970 600,971 603,972 636,973 677,974 680,975 713,976 726,977 730,978 814,979 847,980 851,981 893,982 938,983 947,984 993,985 1008,986 1129,987 1171,988 1211,989 1248,990 1375,991 1461,992 1519,993 1534,994 1599,995 1659,996 1674,997 1732,998 1783,999 1796,1000 1889,1001 1902,1002 1931,1003 1932,1004 1948,1005 1953,1006 1956,1007 2013,1008 2039,1009 2100,1010 2113,1011 2205,1012 2228,1013 2238,1014 2249,1015 2271,1016 2276,1017 2285,1018 2322,1019 2427,1020 2445,1021 2489,1022 2565,1023 2578,1024 2594,1025 2600,1026 2611,1027 2624,1028 2661,1029 2674,1030 2851,1031 2870,1032 2919,1033 2920,1034 2938,1035 2946,1036 2990,1037 2999,1038 3015,1039 3017,1040 3017,1041 3158,1042 3169,1043 3226,1044 3267,1045 3316,1046 3364,1047 3393,1048 3398,1049 3435,1050 3447,1051 3463,1052 3535,1053 3559,1054 3562,1055 3601,1056 3619,1057 3621,1058 3634,1059 3659,1060 3766,1061 3772,1062 3792,1063 3794,1064 3905,1065 3967,1066 3986,1067 3999,1068 4111,1069 4155,1070 4156,1071 4159,1072 4198,1073 4201,1074 4282,1075 4342,1076 4351,1077 4360,1078 4381,1079 4540,1080 4556,1081 4707,1082 4723,1083 4743,1084 4783,1085 4801,1086 4801,1087 4936,1088 4938,1089 4982,1090 5031,1091 5036,1092 5063,1093 5081,1094 5150,1095 5246,1096 5340,1097 5401,1098 5545,1099 5547,1100 5561,1101 5592,1102 5603,1103 5626,1104 5665,1105 5701,1106 5736,1107 5745,1108 5773,1109 5787,1110 5867,1111 5909,1112 6055,1113 6115,1114 6137,1115 6205,1116 6247,1117 6263,1118 6292,1119 6296,1120 6316,1121 6394,1122 6412,1123 6453,1124 6462,1125 6516,1126 6566,1127 6575,1128 6602,1129 6695,1130 6716,1131 6721,1132 6785,1133 6785,1134 6803,1135 6842,1136 7030,1137 7038,1138 7040,1139 7110,1140 7131,1141 7140,1142 7165,1143 7168,1144 7173,1145 7239,1146 7284,1147 7367,1148 7411,1149 7505,1150 7543,1151 7560,1152 7565,1153 7581,1154 7668,1155 7677,1156 7705,1157 7738,1158 7739,1159 7769,1160 7810,1161 7822,1162 7848,1163 7899,1164 7910,1165 7952,1166 7966,1167 8050,1168 8064,1169 8132,1170 8153,1171 8169,1172 8181,1173 8356,1174 8360,1175 8394,1176 8396,1177 8615,1178 8615,1179 8669,1180 8692,1181 8705,1182 8712,1183 8724,1184 8735,1185 8758,1186 8770,1187 8775,1188 8826,1189 8844,1190 8915,1191 8988,1192 9042,1193 9096,1194 9117,1195 9255,1196 9323,1197 9340,1198 9344,1199 9373,1200 9403,