Skip to content

resolve #128-mark-and-toys 문제풀이 및 문서추가 #129

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions Interview-Preparation-Kit/Sorting/mark-and-toys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @title Mark and Toys
* @difficulty Easy
* @link https://www.hackerrank.com/challenges/mark-and-toys/problem
*/

const ascendingCompare = (a, b) => a - b;

function maximumToys(prices, budget) {
const sorted = prices.sort(ascendingCompare);
const {length} = sorted;
let sumPrice = 0;
for (let idx = 0; idx < length; idx++) {
sumPrice += sorted[idx];
if (sumPrice > budget) {
return idx;
}
}

return length;
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Generates the README.md.
| --- | --- | --- |
| Easy | [2D Array - DS](https://www.hackerrank.com/challenges/2d-array/problem) | [Solution](./Interview-Preparation-Kit/Arrays/2d-array-ds.js)|
| Easy | [Left Rotation](https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem) | [Solution](./Interview-Preparation-Kit/Arrays/left-rotation.js)|
#### Sorting
| Difficulty | Problem | Solution |
| --- | --- | --- |
| Easy | [Mark and Toys](https://www.hackerrank.com/challenges/mark-and-toys/problem) | [Solution](./Interview-Preparation-Kit/Sorting/mark-and-toys.js)|
#### Dictionary-and-Hashmap
| Difficulty | Problem | Solution |
| --- | --- | --- |
Expand Down