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