- Notifications
You must be signed in to change notification settings - Fork1.3k
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
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from8 commits
30ac3db
9447151
4ca41ba
daed7dc
7a35db8
83fdb18
b7dc87f
f9b9b6c
423eb11
9bb4d73
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff 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; | ||
} |
Original file line number | Diff line number | Diff 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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |[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 | | ||
@@ -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 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Please remove unrelated changes in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | | ||
Uh oh!
There was an error while loading.Please reload this page.