TomoLink
CompaniesZeptoData Structures & AlgorithmsShuffle an Array
DSA
MediumArray

Shuffle an Array

arraymathdesign

Problem Statement

Given an integer array nums , design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.

Implement the Solution class:

Solution(int[] nums) Initializes the object with the integer array nums .

int[] reset() Resets the array to its original configuration and returns it.

int[] shuffle() Returns a random shuffling of the array.

Examples

Example 1
Input:
Output:

Constraints

1 <= nums.length <= 50
-10 ^6 <= nums[i] <= 10 ^6
All the elements of nums are unique .
At most 10 ^4 calls in total will be made to reset and shuffle .
🤔
Medium
Difficulty
Topic Info
ModuleDSA
CategoryArray
Sub-topicMath
Tags
arraymathdesignrandomized
Navigation
Shuffle an Array [Medium] | Zepto Dsa | TomoLink