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

added two js solutions. problems 3016 && 3175#194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
sambabib wants to merge10 commits intofishercoder1534:master
base:master
Choose a base branch
Loading
fromsambabib:sambabib-js-solutions
Open
Show file tree
Hide file tree
Changes from8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletionsjavascript/_3016.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
function minPushesToType(word) {
let freqMap = new Map();

// Using greedy frequency-based allocation (this is basically gives pirority based on frequenecy of occurence.).
// Count frequency of each letter.
for (let char of word) {
freqMap.set(char, (freqMap.get(char) || 0) + 1);
}

// Sort letters by frequency in descending order.
let frequencies = Array.from(freqMap.values()).sort((a, b) => b - a);

// Assign letters to keys 2-9.
let keys = Array(8).fill(0);
let totalPushes = 0;

for (let i = 0; i < frequencies.length; i++) {
let keyIndex = i % 8;
let presses = Math.floor(i / 8) + 1;
totalPushes += frequencies[i] * presses;
}

return totalPushes;
}
25 changes: 25 additions & 0 deletionsjavascript/_3175.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
function findWinner(skills, k) {
// This solution uses a queue to process the matches.
let n = skills.length;
let maxSkill = Math.max(...skills);
let queue = [];

let currentWinner = 0;
let currentWins = 0;

for (let i = 1; i < n; i++) {
if (skills[currentWinner] > skills[i]) {
currentWins++;
} else {
currentWinner = i;
currentWins = 1;
}

// If the champion has won k times or is the max skill player, return.
if (currentWins >= k || skills[currentWinner] === maxSkill) {
return currentWinner;
}
}

return currentWinner;
}
8 changes: 7 additions & 1 deletionpaginated_contents/algorithms/4th_thousand/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,7 +67,7 @@
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
Expand DownExpand Up@@ -103,6 +103,12 @@
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 3032 | [Count Numbers With Unique Digits II](https://leetcode.com/problems/count-numbers-with-unique-digits-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3032.java) | | Easy |
| 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 |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please remove unrelated changes in this PR.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The changes from the .README was indentation misdirected on my part. I have resolved them now, if I haven't, please let me know what I am missing. Thanks

| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp