Created
July 29, 2025 19:07
-
-
Save colinlord/454150d639ca954b3d7867eb39cec6e1 to your computer and use it in GitHub Desktop.
Cassidy Interview QOTW: 7/28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given an array of side lengths, write a function to determine | |
// they can form a hexagon with three side-length pairs (as in, | |
// three pairs of equal sides needed). Return true if possible. | |
function canFormHexagon(sides) { | |
if (!Array.isArray(sides) || sides.length !== 6) { | |
return false; | |
} | |
const frequencyMap = {}; | |
for (const side of sides) { | |
frequencyMap[side] = (frequencyMap[side] || 0) + 1; | |
} | |
const counts = Object.values(frequencyMap); | |
if (counts.length !== 3) { | |
return false; | |
} | |
return counts.every(count => count === 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment