Skip to content

Commit a78470d

Browse files
committed
Added more variant solutions to some problems
1 parent 2f808b5 commit a78470d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Equalize-the-array/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ function equalizeArray(arr) {
1212
}
1313

1414
return minLength;
15+
16+
// // A more efficient solution, O(n) time complexity
17+
// // Array for counting the frequency, also called Hashmap
18+
// const frequency = [];
19+
20+
// for (let i = 0; i <= 100; i++) frequency[i] = 0;
21+
// for (let i = 0; i < arr.length; i++) frequency[arr[i]]++;
22+
23+
// return arr.length - Math.max(...frequency);
1524
}
1625

1726
// Test cases
1827
console.log(equalizeArray([1, 2, 2, 3])); // 2
1928
console.log(equalizeArray([3, 3, 2, 1, 3])); // 2
2029
console.log(equalizeArray([1, 2, 3, 1, 2, 3, 3, 3])); // 4
2130
console.log(equalizeArray([-1, 2, -1, 1, 2, 3, 3, 3])); // 5
22-

Halloween Sale/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function howManyGames(p, d, m, s) {
77
while (s >= m && (s - p) >= 0) {
88
s -= p;
99
p = ((p - d) <= m) ? m : (p - d);
10+
// OR
11+
// p = Math.max(m, p - d);
1012
numOfGames++;
1113
}
1214

0 commit comments

Comments
 (0)