Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7dc87f

Browse files
author
sambabib
committed
added js solutions to _3016 && _3175
1 parent83fdb18 commitb7dc87f

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

‎javascript/_3016.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
functionminPushesToType(word){
2+
letfreqMap=newMap();
3+
4+
// Using greedy frequency-based allocation (this is basically gives pirority based on frequenecy of occurence.).
5+
// Count frequency of each letter.
6+
for(letcharofword){
7+
freqMap.set(char,(freqMap.get(char)||0)+1);
8+
}
9+
10+
// Sort letters by frequency in descending order.
11+
letfrequencies=Array.from(freqMap.values()).sort((a,b)=>b-a);
12+
13+
// Assign letters to keys 2-9.
14+
letkeys=Array(8).fill(0);
15+
lettotalPushes=0;
16+
17+
for(leti=0;i<frequencies.length;i++){
18+
letkeyIndex=i%8;
19+
letpresses=Math.floor(i/8)+1;
20+
totalPushes+=frequencies[i]*presses;
21+
}
22+
23+
returntotalPushes;
24+
}

‎javascript/_3175.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
functionfindWinner(skills,k){
2+
// This solution uses a queue to process the matches.
3+
letn=skills.length;
4+
letmaxSkill=Math.max(...skills);
5+
letqueue=[];
6+
7+
letcurrentWinner=0;
8+
letcurrentWins=0;
9+
10+
for(leti=1;i<n;i++){
11+
if(skills[currentWinner]>skills[i]){
12+
currentWins++;
13+
}else{
14+
currentWinner=i;
15+
currentWins=1;
16+
}
17+
18+
// If the champion has won k times or is the max skill player, return.
19+
if(currentWins>=k||skills[currentWinner]===maxSkill){
20+
returncurrentWinner;
21+
}
22+
}
23+
24+
returncurrentWinner;
25+
}

‎paginated_contents/algorithms/4th_thousand/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
| 3185|[Count Pairs That Form a Complete Day II](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-ii/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3185.java)|| Medium|
4343
| 3184|[Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3184.java)|| Easy|
4444
| 3178|[Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3178.java)|| Easy|
45-
| 3175|[Find The First Player to win K Games in a Row](https://leetcode.com/problems/find-the-first-player-to-win-k-games-in-a-row/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3175.java)|| Medium|
45+
| 3175|[Find The First Player to win K Games in a Row](https://leetcode.com/problems/find-the-first-player-to-win-k-games-in-a-row/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3175.java)|[Javascript](https://github.com/fishercoder1534/Leetcode/blob/master/javascript/_3175.js)| Medium|
4646
| 3174|[Clear Digits](https://leetcode.com/problems/clear-digits/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3174.java)|| Easy|
4747
| 3173|[Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3173.java)|| Easy|
4848
| 3168|[Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3168.java)|| Easy|
@@ -78,7 +78,7 @@
7878
| 3024|[Type of Triangle](https://leetcode.com/problems/type-of-triangle/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3024.java)|| Easy|
7979
| 3028|[Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3028.java)|| Easy|
8080
| 3019|[Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3019.java)|| Easy|
81-
| 3016|[Minimum Number of Pushes to Type Word II](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3016.java)|| Medium|
81+
| 3016|[Minimum Number of Pushes to Type Word II](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3016.java)|[Javascript](https://github.com/fishercoder1534/Leetcode/blob/master/javascript/_3016.js)| Medium|
8282
| 3010|[Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3010.java)|| Easy|
8383
| 3014|[Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3014.java)|| Easy|
8484
| 3006|[Find Beautiful Indices in the Given Array I](https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3006.java)|| Medium|

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp