Skip to content

Commit 16b93e3

Browse files
committed
할인 행사 / 심화
1 parent d2301ff commit 16b93e3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function solution(want, number, discount) {
2+
const required = {};
3+
want.forEach((item, index) => {
4+
required[item] = number[index];
5+
});
6+
7+
let day = 0;
8+
9+
for (let i = 0; i <= discount.length - 10; i++) {
10+
const current = {};
11+
12+
for (let j = i; j < i + 10; j++) {
13+
current[discount[j]] = (current[discount[j]] || 0) + 1;
14+
}
15+
16+
const isValid = want.every(
17+
(item) => (current[item] || 0) >= required[item]
18+
);
19+
20+
if (isValid) day++;
21+
}
22+
23+
return day;
24+
}

0 commit comments

Comments
 (0)