// Time: O(n) // Space: O(n) class Solution { public: Solution(vector nums) : nums_(nums) { } /** Resets the array to its original configuration and return it. */ vector reset() { return nums_; } /** Returns a random shuffling of the array. */ vector shuffle() { vector nums{nums_}; default_random_engine seed((random_device())()); for (int i = 0; i < nums.size(); ++i) { swap(nums[i], nums[uniform_int_distribution{ i, static_cast(nums.size()) - 1}(seed)]); } return nums; } private: const vector nums_; }; /** * Your Solution object will be instantiated and called as such: * Solution obj = new Solution(nums); * vector param_1 = obj.reset(); * vector param_2 = obj.shuffle(); */