Requirement is to develop/code an algorithm that will re-arrange a group/list of data according to following rules -1) Determine optimal number of primarily 4, and 5 or 3 number sub-groups to divide group into (existing code)2) Keep "1" ranks together - even if two names are on same team 2a) Give the largest sub-group to the highest ranking names 2b) Keep "1" and "2" ranks together as much as possible 2c) Fill in sub-groups with "3"s and "4"s3) Separate teams as much as possible. No sub-group should have more than one name from the same team if it can be helped.Data is imported from external file or Db (can be > 1000 rows) and read into array - $w['ID'] UNIQUE $w['TEAM'] 1 to n occurances $w['NAME'] $w['AGE'] values 5-14 $w['WEIGHT'] values range 30-285 $w['RANK'] values 1-5Data is then run thru existing code which groups it by age/weight and then sorts each group by rank,as shown below (# is for reference in this post) - # ID TEAM NAME AGE WHT RANK 1 97 ONW name 8 55 1 2 95 HIG name 8 55 1 3 96 BVW name 8 55 1 4 91 NLD name 8 55 1 5 90 NLD name 8 55 1 6 92 OKG name 8 55 1 7 106 RIC name 8 55 2 8 89 NLD name 8 55 2 9 110 LSB name 8 55 210 104 TWI name 8 55 211 102 IND name 8 55 212 99 LIB name 8 55 313 105 TWI name 8 55 314 107 BEL name 8 55 315 93 MOW name 8 55 316 98 ONW name 8 55 417 88 LEE name 8 55 418 94 MOW name 8 55 419 101 IND name 8 55 420 112 LSB name 8 55 421 108 SWA name 8 55 422 100 ODE name 8 55 423 111 LSB name 8 55 424 109 LSB name 8 55 425 103 IND name 8 55 5Requirement is to develop/code an algorithm that will re-arrange the group according to following rules -1) Determine optimal number of primarily 4, and 5 or 3 number sub-groups to divide group into (existing code)2) Keep "1" ranks together - even if two names are on same team 2a) Give the largest sub-group to the highest ranking names 2b) Keep "1" and "2" ranks together as much as possible 2c) Fill in sub-groups with "3"s and "4"s3) Separate teams as much as possible. No sub-group should have more than one name from the same team if it can be helped.This was done manually to this subset -25 names divided into 5 groups of 4 & 1 group of 5.Put first 5 "1"s into sub-group of 5.Moved 90/NLD from 5 to 6 and 92/OKG from 6 to 5 to separate the two NLD teams.Others moved up/down to prevent remaining sub-groups of 4 from having more than one team member - to the extent possible 1 97 ONW name 8 55 1 2 95 HIG name 8 55 1 3 96 BVW name 8 55 1 4 91 NLD name 8 55 1 6 92 OKG name 8 55 1 5 90 NLD name 8 55 1 7 106 RIC name 8 55 2 9 110 LSB name 8 55 211 102 IND name 8 55 210 104 TWI name 8 55 2 8 89 NLD name 8 55 212 99 LIB name 8 55 314 107 BEL name 8 55 313 105 TWI name 8 55 315 93 MOW name 8 55 316 98 ONW name 8 55 420 112 LSB name 8 55 418 94 MOW name 8 55 419 101 IND name 8 55 417 88 LEE name 8 55 423 111 LSB name 8 55 421 108 SWA name 8 55 422 100 ODE name 8 55 424 109 LSB name 8 55 425 103 IND name 8 55 5Above prepares the list to be sent to an existing code function that creates the sub-groups. This is the final outcome -8-55a 97 ONW name 8 55 1 95 HIG name 8 55 1 96 BVW name 8 55 1 91 NLD name 8 55 1 92 OKG name 8 55 18-55b 90 NLD name 8 55 1106 RIC name 8 55 2110 LSB name 8 55 2102 IND name 8 55 28-55c104 TWI name 8 55 2 89 NLD name 8 55 2 99 LIB name 8 55 3107 BEL name 8 55 38-55d105 TWI name 8 55 3 93 MOW name 8 55 3 98 ONW name 8 55 4112 LSB name 8 55 48-55e 94 MOW name 8 55 4101 IND name 8 55 4 88 LEE name 8 55 4111 LSB name 8 55 48-55f108 SWA name 8 55 4100 ODE name 8 55 4109 LSB name 8 55 4103 IND name 8 55 5