Skip to content

Commit 7929e9a

Browse files
committed
Add solution #1626
1 parent b6173b9 commit 7929e9a

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,430 LeetCode solutions in JavaScript
1+
# 1,431 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1254,6 +1254,7 @@
12541254
1622|[Fancy Sequence](./solutions/1622-fancy-sequence.js)|Hard|
12551255
1624|[Largest Substring Between Two Equal Characters](./solutions/1624-largest-substring-between-two-equal-characters.js)|Easy|
12561256
1625|[Lexicographically Smallest String After Applying Operations](./solutions/1625-lexicographically-smallest-string-after-applying-operations.js)|Medium|
1257+
1626|[Best Team With No Conflicts](./solutions/1626-best-team-with-no-conflicts.js)|Medium|
12571258
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12581259
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
12591260
1669|[Merge In Between Linked Lists](./solutions/1669-merge-in-between-linked-lists.js)|Medium|
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* 1626. Best Team With No Conflicts
3+
* https://leetcode.com/problems/best-team-with-no-conflicts/
4+
* Difficulty: Medium
5+
*
6+
* You are the manager of a basketball team. For the upcoming tournament, you want to choose the
7+
* team with the highest overall score. The score of the team is the sum of scores of all the
8+
* players in the team.
9+
*
10+
* However, the basketball team is not allowed to have conflicts. A conflict exists if a younger
11+
* player has a strictly higher score than an older player. A conflict does not occur between
12+
* players of the same age.
13+
*
14+
* Given two lists, scores and ages, where each scores[i] and ages[i] represents the score and
15+
* age of the ith player, respectively, return the highest overall score of all possible basketball
16+
* teams.
17+
*/
18+
19+
/**
20+
* @param {number[]} scores
21+
* @param {number[]} ages
22+
* @return {number}
23+
*/
24+
var bestTeamScore = function(scores, ages) {
25+
const players = ages.map((age, index) => ({ age, score: scores[index] }));
26+
players.sort((a, b) => a.age - b.age || a.score - b.score);
27+
28+
const maxScores = new Array(players.length).fill(0);
29+
let highestScore = 0;
30+
31+
for (let current = 0; current < players.length; current++) {
32+
maxScores[current] = players[current].score;
33+
for (let previous = 0; previous < current; previous++) {
34+
if (players[previous].score <= players[current].score) {
35+
maxScores[current] = Math.max(
36+
maxScores[current],
37+
maxScores[previous] + players[current].score
38+
);
39+
}
40+
}
41+
highestScore = Math.max(highestScore, maxScores[current]);
42+
}
43+
44+
return highestScore;
45+
};

0 commit comments

Comments
 (0)