Class Photos
Class Photos
// O(nlog(n)) time | O(1) space
function classPhotos(redShirtHeights, blueShirtHeights) {
redShirtHeights.sort((a, b) => b - a);
blueShirtHeights.sort((a, b) => b - a);
const shirtColorFirstRow = redShirtHeights[0] < blueShirtHeights[0] ? "RED" : "BLUE";
for (let i = 0; i < redShirtHeights.length; i++) {
const redHeight = redShirtHeights[i]
const blueHeight = blueShirtHeights[i];
if (shirtColorFirstRow === 'RED') {
if (redHeight >= blueHeight) return false;
} else if (blueHeight >= redHeight) return false
}
return true;
}
// Do not edit the line below.
exports.classPhotos = classPhotos;
Last updated