FPEvalDataset/LeetCodeProblem
0302
1{2 "id": 3244,3 "name": "minimize_length_of_array_using_operations",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/minimize-length-of-array-using-operations/",6 "date": "2024-01-06 00:00:00",7 "task_description": "You are given a **0-indexed** integer array `nums` containing **positive** integers. Your task is to **minimize** the length of `nums` by performing the following operations **any** number of times (including zero): Select **two** **distinct** indices `i` and `j` from `nums`, such that `nums[i] > 0` and `nums[j] > 0`. Insert the result of `nums[i] % nums[j]` at the end of `nums`. Delete the elements at indices `i` and `j` from `nums`. Return _an integer denoting the **minimum** **length** of _`nums`_ after performing the operation any number of times._ **Example 1:** ``` **Input:** nums = [1,4,3,1] **Output:** 1 **Explanation:** One way to minimize the length of the array is as follows: Operation 1: Select indices 2 and 1, insert nums[2] % nums[1] at the end and it becomes [1,4,3,1,3], then delete elements at indices 2 and 1. nums becomes [1,1,3]. Operation 2: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [1,1,3,1], then delete elements at indices 1 and 2. nums becomes [1,1]. Operation 3: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [1,1,0], then delete elements at indices 1 and 0. nums becomes [0]. The length of nums cannot be reduced further. Hence, the answer is 1. It can be shown that 1 is the minimum achievable length. ``` **Example 2:** ``` **Input:** nums = [5,5,5,10,5] **Output:** 2 **Explanation:** One way to minimize the length of the array is as follows: Operation 1: Select indices 0 and 3, insert nums[0] % nums[3] at the end and it becomes [5,5,5,10,5,5], then delete elements at indices 0 and 3. nums becomes [5,5,5,5]. Operation 2: Select indices 2 and 3, insert nums[2] % nums[3] at the end and it becomes [5,5,5,5,0], then delete elements at indices 2 and 3. nums becomes [5,5,0]. Operation 3: Select indices 0 and 1, insert nums[0] % nums[1] at the end and it becomes [5,5,0,0], then delete elements at indices 0 and 1. nums becomes [0,0]. The length of nums cannot be reduced further. Hence, the answer is 2. It can be shown that 2 is the minimum achievable length. ``` **Example 3:** ``` **Input:** nums = [2,3,4] **Output:** 1 **Explanation:** One way to minimize the length of the array is as follows: Operation 1: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [2,3,4,3], then delete elements at indices 1 and 2. nums becomes [2,3]. Operation 2: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [2,3,1], then delete elements at indices 1 and 0. nums becomes [1]. The length of nums cannot be reduced further. Hence, the answer is 1. It can be shown that 1 is the minimum achievable length. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 109`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "nums = [1,4,3,1]",12 "output": "1 "13 },14 {15 "label": "Example 2",16 "input": "nums = [5,5,5,10,5]",17 "output": "2 "18 },19 {20 "label": "Example 3",21 "input": "nums = [2,3,4]",22 "output": "1 "23 }24 ],25 "private_test_cases": [26 {27 "input": [28 7,29 5,30 3,31 2,32 433 ],34 "output": 135 },36 {37 "input": [38 65,39 7,40 5,41 67,42 75,43 39,44 34,45 13,46 48,47 6548 ],49 "output": 150 },51 {52 "input": [53 895,54 535,55 66,56 348,57 458,58 823,59 698,60 558,61 55,62 155,63 340,64 252,65 115,66 433,67 59,68 14,69 610,70 890,71 533,72 305,73 356,74 823,75 380,76 965,77 881,78 252,79 489,80 852,81 562,82 171,83 990,84 976,85 28,86 82,87 820,88 192,89 275,90 618,91 79,92 752,93 504,94 720,95 519,96 115,97 507,98 255,99 298,100 86,101 108,102 417,103 437,104 935,105 371,106 704,107 962,108 333,109 487,110 478,111 640,112 203,113 94,114 709,115 269,116 173,117 375,118 538,119 488,120 101,121 986,122 899,123 58,124 543,125 167,126 701,127 212,128 226,129 671,130 562,131 728,132 969,133 733,134 647,135 825,136 117,137 968,138 364,139 434,140 161,141 311,142 623,143 615,144 717,145 482,146 945,147 313,148 134,149 520,150 390,151 499,152 756,153 614,154 454,155 987,156 129,157 155,158 523,159 544,160 935,161 130,162 885,163 89,164 338,165 423,166 950,167 933,168 949,169 40,170 644,171 769,172 272,173 236,174 873,175 337,176 211,177 349,178 930,179 253,180 499,181 788,182 843,183 632,184 330,185 257,186 333,187 47,188 843,189 914,190 490,191 939,192 721,193 733,194 44,195 898,196 192,197 528,198 306,199 260,200 358,201 95,202 424,203 804,204 496,205 973,206 322,207 391,208 664,209 257,210 147,211 684,212 389,213 803,214 326,215 15,216 697,217 140,218 105,219 929,220 316,221 310,222 56,223 726,224 583,225 954,226 388,227 452,228 416,229 446,230 112,231 200,232 134,233 495,234 232,235 361,236 915,237 538,238 199,239 853,240 771,241 562,242 868,243 342,244 936,245 276,246 770,247 120,248 108,249 28,250 474,251 903,252 772,253 962,254 728,255 340,256 928,257 671,258 889,259 13,260 263,261 589,262 916,263 476,264 501,265 310,266 501,267 879,268 538,269 806,270 864,271 769,272 409,273 838,274 198,275 81,276 755,277 166,278 476,279 824,280 461,281 182,282 231,283 171,284 669,285 643,286 689,287 513,288 745,289 357,290 217,291 784,292 583,293 195,294 810,295 42,296 133,297 645,298 28,299 334,300 245,301 155,302 27,303 352,304 139,305 982,306 943,307 211,308 217,309 775,310 182,311 924,312 443,313 984,314 265,315 96,316 24,317 668,318 987,319 77,320 825,321 685,322 705,323 209,324 132,325 20,326 891,327 50,328 498,329 383,330 473,331 917,332 151,333 177,334 451,335 692,336 725,337 393,338 666,339 771,340 215,341 862,342 451,343 11,344 998,345 158,346 714,347 467,348 918,349 771,350 340,351 359,352 838,353 889,354 253,355 534,356 263,357 38,358 323,359 717,360 331,361 125,362 182,363 656,364 155,365 668,366 505,367 91,368 341,369 157,370 393,371 234,372 343,373 296,374 970,375 608,376 521,377 111,378 310,379 606,380 908,381 208,382 660,383 477,384 596,385 202,386 821,387 250,388 469,389 593,390 753,391 320,392 806,393 503,394 892,395 471,396 148,397 253,398 146,399 634,400 165,401 555,402 103,403 268,404 570,405 531,406 1000,407 158,408 846,409 856,410 852,411 596,412 710,413 922,414 202,415 313,416 24,417 276,418 493,419 617,420 337,421 631,422 867,423 66,424 131,425 254,426 262,427 543,428 676,429 846,430 50,431 499,432 504,433 502,434 536,435 110,436 500,437 11,438 428,439 810,440 237,441 702,442 926,443 143,444 5,445 547,446 625,447 599,448 681,449 960,450 627,451 282,452 273,453 835,454 932,455 538,456 691,457 366,458 336,459 849,460 505,461 399,462 693,463 480,464 652,465 303,466 847,467 104,468 662,469 96,470 696,471 986,472 977,473 831,474 164,475 57,476 236,477 471,478 542,479 629,480 519,481 351,482 316,483 228,484 380,485 418,486 375,487 973,488 707,489 970,490 168,491 467,492 262,493 737,494 681,495 723,496 514,497 403,498 298,499 265,500 155,501 794,502 220,503 809,504 737,505 457,506 990,507 420,508 917,509 488,510 685,511 302,512 222,513 993,514 792,515 26,516 800,517 577,518 840,519 258,520 213,521 406,522 21,523 32,524 101,525 844,526 798,527 916,528 400,529 130,530 710,531 700,532 302,533 171,534 379,535 595,536 118,537 237,538 21,539 734,540 27,541 980,542 753,543 688,544 191,545 476,546 234,547 128,548 718,549 317,550 465,551 755,552 751,553 159,554 869,555 202,556 489,557 78,558 867,559 303,560 775,561 886,562 711,563 204,564 716,565 138,566 615,567 819,568 478,569 622,570 801,571 474,572 632,573 681,574 319,575 183,576 212,577 725,578 65,579 948,580 563,581 556,582 232,583 445,584 993,585 126,586 464,587 317,588 450,589 160,590 699,591 560,592 280,593 688,594 178,595 303,596 166,597 358,598 94,599 751,600 891,601 261,602 805,603 648,604 552,605 428,606 826,607 745,608 387,609 957,610 411,611 776,612 40,613 398,614 430,615 835,616 195,617 14,618 988,619 630,620 204,621 789,622 590,623 809,624 978,625 322,626 975,627 436,628 983,629 356,630 895,631 725,632 911,633 107,634 724,635 226,636 943,637 788,638 429,639 741,640 240,641 809,642 325,643 796,644 251,645 380,646 395,647 949,648 277,649 931,650 121,651 301,652 633,653 977,654 608,655 81,656 46,657 838,658 807,659 436,660 202,661 273,662 853,663 369,664 735,665 692,666 111,667 804,668 43,669 802,670 838,671 287,672 51,673 221,674 603,675 92,676 361,677 763,678 177,679 883,680 827,681 370,682 242,683 841,684 317,685 638,686 725,687 610,688 357,689 965,690 677,691 27,692 607,693 909,694 117,695 405,696 246,697 747,698 624,699 168,700 159,701 425,702 111,703 704,704 473,705 52,706 402,707 85,708 914,709 123,710 21,711 139,712 47,713 904,714 286,715 108,716 713,717 304,718 47,719 655,720 474,721 378,722 319,723 821,724 62,725 400,726 894,727 668,728 823,729 601,730 403,731 236,732 474,733 873,734 282,735 982,736 807,737 808,738 530,739 740,740 268,741 886,742 623,743 261,744 673,745 775,746 543,747 581,748 989,749 623,750 513,751 779,752 352,753 316,754 934,755 496,756 764,757 902,758 103,759 675,760 67,761 572,762 488,763 314,764 194,765 821,766 437,767 74,768 989,769 937,770 859,771 576,772 114,773 925,774 87,775 230,776 778,777 869,778 839,779 635,780 106,781 846,782 845,783 316,784 857,785 207,786 389,787 568,788 432,789 86,790 380,791 460,792 800,793 497,794 191,795 830,796 401,797 490,798 816,799 967,800 595,801 397,802 557,803 943,804 858,805 581806 ],807 "output": 1808 },809 {810 "input": [811 3721,812 332,813 7193,814 3646,815 7062,816 4704,817 6262,818 4369,819 8052,820 3640,821 8655,822 9043,823 7741,824 2130,825 6761,826 2336,827 8367,828 3725,829 8659,830 9759,831 7038,832 9190,833 2703,834 2665,835 9834,836 2287,837 4351,838 4548,839 7896,840 4637,841 1349,842 4258,843 3135,844 8522,845 5425,846 5142,847 7611,848 2352,849 253,850 1118,851 6364,852 3002,853 7801,854 9328,855 9234,856 3367,857 5276,858 7319,859 8683,860 3484,861 3970,862 6919,863 2176,864 2471,865 364,866 1819,867 4556,868 3441,869 4405,870 5333,871 9121,872 9598,873 7396,874 3891,875 3406,876 6566,877 3247,878 1505,879 6232,880 6880,881 51,882 5129,883 223,884 1246,885 9562,886 3930,887 1017,888 2742,889 2720,890 4777,891 2904,892 9647,893 9935,894 5929,895 7279,896 5719,897 3017,898 3390,899 1813,900 6660,901 5491,902 1691,903 7873,904 5277,905 2819,906 8786,907 1767,908 5346,909 5858,910 3338,911 8626,912 2655,913 6228,914 8895,915 1675,916 1206,917 5951,918 3707,919 2932,920 7322,921 5885,922 3241,923 5449,924 8221,925 1581,926 4373,927 8269,928 5770,929 8894,930 8837,931 4469,932 5096,933 3382,934 6760,935 6343,936 5279,937 9948,938 2372,939 8375,940 2186,941 1755,942 2450,943 1478,944 9408,945 2390,946 3334,947 8800,948 1245,949 8366,950 9040,951 5554,952 6115,953 6953,954 7472,955 6612,956 1244,957 2363,958 5153,959 301,960 9310,961 7481,962 4678,963 432,964 115,965 5752,966 5208,967 2822,968 5789,969 7237,970 1747,971 9259,972 93,973 2411,974 1715,975 9117,976 8548,977 394,978 2942,979 534,980 2198,981 7050,982 1824,983 4490,984 8519,985 8164,986 464,987 8455,988 6350,989 295,990 2861,991 9809,992 3255,993 9852,994 1021,995 1473,996 7377,997 4613,998 4154,999 3717,1000 5558,1001 4647,1002 1693,1003 2714,1004 4889,1005 7559,1006 5775,1007 8978,1008 3702,1009 5053,1010 1672,1011 1938,1012 7194,1013 9886,1014 9711,1015 2970,1016 6434,1017 6504,1018 191,1019 5522,1020 8708,1021 1000,1022 7974,1023 1979,1024 6675,1025 5010,1026 3977,1027 8214,1028 4879,1029 8065,1030 6687,1031 9502,1032 1105,1033 6808,1034 6555,1035 9537,1036 7782,1037 3283,1038 5950,1039 7207,1040 5616,1041 933,1042 514,1043 2252,1044 7454,1045 5292,1046 2966,1047 8707,1048 2708,1049 2088,1050 3167,1051 5780,1052 1747,1053 7271,1054 8556,1055 2156,1056 7239,1057 2373,1058 7927,1059 3431,1060 3570,1061 1150,1062 3465,1063 7850,1064 6456,1065 1145,1066 957,1067 2814,1068 5372,1069 5526,1070 309,1071 8786,1072 5734,1073 3298,1074 6424,1075 7418,1076 5994,1077 2004,1078 267,1079 7733,1080 5212,1081 4763,1082 1736,1083 1815,1084 8736,1085 932,1086 2902,1087 8421,1088 5918,1089 6992,1090 8636,1091 9402,1092 1567,1093 3372,1094 5128,1095 6580,1096 4384,1097 7039,1098 8428,1099 5260,1100 4923,1101 6958,1102 5491,1103 5420,1104 9382,1105 2853,1106 6080,1107 5015,1108 1897,1109 7617,1110 2234,1111 3158,1112 1411,1113 1924,1114 9699,1115 9016,1116 7707,1117 6567,1118 5850,1119 5186,1120 5709,1121 1951,1122 9878,1123 7080,1124 5069,1125 9383,1126 3971,1127 3457,1128 4332,1129 3645,1130 1801,1131 1836,1132 9526,1133 3869,1134 4335,1135 420,1136 5348,1137 8939,1138 5893,1139 6172,1140 6144,1141 3072,1142 1704,1143 4080,1144 3844,1145 2178,1146 7107,1147 1623,1148 4292,1149 1472,1150 377,1151 3296,1152 8048,1153 3477,1154 608,1155 8251,1156 1846,1157 4063,1158 7261,1159 2319,1160 6773,1161 9877,1162 5562,1163 5058,1164 1532,1165 5628,1166 9269,1167 5996,1168 1361,1169 8730,1170 8,1171 66,1172 6079,1173 4460,1174 3008,1175 4334,1176 2242,1177 9717,1178 5635,1179 5921,1180 1844,1181 8586,1182 499,1183 4982,1184 622,1185 3498,1186 7012,1187 365,1188 8242,1189 2363,1190 2586,1191 6650,1192 1514,1193 5177,1194 8146,1195 9185,1196 6838,1197 126,1198 760,1199 9382,1200 6060,