This is the solution to day 04 daily problem in october!
This code pairs up players based on their skill levels to form teams with equal total skill. It first sorts the skill levels, then checks if the sum of skills for each pair (one from the start and one from the end) matches the required sum (calculated from the first and last player's skill). If any pair doesn't match, it returns -1, indicating it's impossible to evenly divide the players. Otherwise, it calculates the total chemistry (product of paired players' skills) and returns it.
This is the solution to day 04 daily problem in october!
This code pairs up players based on their skill levels to form teams with equal total skill. It first sorts the skill levels, then checks if the sum of skills for each pair (one from the start and one from the end) matches the required sum (calculated from the first and last player's skill). If any pair doesn't match, it returns
-1
, indicating it's impossible to evenly divide the players. Otherwise, it calculates the total chemistry (product of paired players' skills) and returns it.