Skip to content

Instantly share code, notes, and snippets.

@colinlord
Created July 29, 2025 19:07
Show Gist options
  • Save colinlord/454150d639ca954b3d7867eb39cec6e1 to your computer and use it in GitHub Desktop.
Save colinlord/454150d639ca954b3d7867eb39cec6e1 to your computer and use it in GitHub Desktop.
Cassidy Interview QOTW: 7/28
// 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