Skip to content

Commit 6d46d59

Browse files
committed
Add prompt for LC 84 Shuffle an Array
1 parent 3ad6dbf commit 6d46d59

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

384. Shuffle an Array.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
3+
LeetCode Problem 384: Shuffle an Array
4+
5+
Description:
6+
Given an integer array nums, design an algorithm to randomly shuffle the array.
7+
All permutations of the array should be equally likely as a result of the shuffling.
8+
9+
Implementation of the Solution class:
10+
- Solution(int[] nums): Initializes the object with the integer array nums.
11+
- int[] reset(): Resets the array to its original configuration and returns it.
12+
- int[] shuffle(): Returns a random shuffling of the array.
13+
14+
Example Usage:
15+
const solution = new Solution([1, 2, 3]);
16+
console.log(solution.shuffle()); // Example output: [3, 1, 2]
17+
console.log(solution.reset()); // Output: [1, 2, 3]
18+
console.log(solution.shuffle()); // Example output: [1, 3, 2]
19+
20+
Constraints:
21+
- 1 <= nums.length <= 50
22+
- -10^6 <= nums[i] <= 10^6
23+
- All elements in nums are unique.
24+
- At most 10,000 calls in total will be made to reset and shuffle.
25+
26+
*/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ LeetCode Profile: https://leetcode.com/timothyshores/
3636
|[229. Bulls And Cows](https://leetcode.com/problems/bulls-and-cows)|Medium|[JavaScript](229.%20Bulls%20And%20Cows.js)
3737
|[326. Power of Three](https://leetcode.com/problems/power-of-three/)|Easy|[JavaScript](326.%20Power%20of%20Three.js)
3838
|[345. Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string/)|Easy|[JavaScript](345.%20Reverse%20Vowels%20of%20a%20String.js)
39+
|[384. Shuffle an Array](https://leetcode.com/problems/shuffle-an-array/)|Medium|[JavaScript](384.%20Shuffle%20an%20Array.js)
3940
|[387. First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/)|Easy|[JavaScript](387.%20First%20Unique%20Character%20in%20a%20String.js)
4041
|[482. License Key Formatting](https://leetcode.com/problems/license-key-formatting/)|Easy|[JavaScript](482.%20License%20Key%20Formatting.js)
4142
|[509. Fibonacci Number](https://leetcode.com/problems/fibonacci-number/)|Easy|[JavaScript](509.%20Fibonacci%20Number.js)

0 commit comments

Comments
 (0)