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