From 78c934a98b5d6072786413144a9d81913ff1e5a3 Mon Sep 17 00:00:00 2001 From: TK Date: Sun, 10 Dec 2023 09:49:22 -0300 Subject: [PATCH] * --- .../algoexpert/class-photos/class-photos.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 coding_interviews/algoexpert/class-photos/class-photos.js diff --git a/coding_interviews/algoexpert/class-photos/class-photos.js b/coding_interviews/algoexpert/class-photos/class-photos.js new file mode 100644 index 0000000..23167c2 --- /dev/null +++ b/coding_interviews/algoexpert/class-photos/class-photos.js @@ -0,0 +1,21 @@ +function classPhotos(redShirtHeights, blueShirtHeights) { + redShirtHeights.sort((a, b) => a - b); + blueShirtHeights.sort((a, b) => a - b); + + let backRow; + let frontRow; + + if (redShirtHeights[0] < blueShirtHeights[0]) { + backRow = blueShirtHeights; + frontRow = redShirtHeights; + } else { + backRow = redShirtHeights; + frontRow = blueShirtHeights; + } + + for (let index = 0; index < backRow.length; index++) { + if (frontRow[index] >= backRow[index]) return false; + } + + return true; +}