Why cant orders be different as compared to solution set


  • 0
    S

    A shuffle of an array can give you any order.. then on what basis can we match the solution set ??
    p.s. my testcases are failing due to this :P

    public class Solution {
        int[] originalArray;
        
        public Solution(int[] nums) {
            originalArray = new int[nums.length];
            System.arraycopy(nums, 0, originalArray, 0, nums.length);
        }
        
        /** Resets the array to its original configuration and return it. */
        public int[] reset() {
           return originalArray;  
        }
        
        /** Returns a random shuffling of the array. */
        public int[] shuffle() {
            int n = originalArray.length;
            int[] output = new int[n];
            int[] temp = new int[n];
            System.arraycopy(originalArray, 0, output, 0, n);
            
            for(int i=0; i < n; i++){
                int random = (int)Math.floor(Math.random() * (n-i-1));    
                temp[i] = output[random];
                output[random] = output[n-i-1];
                output[n-i-1] = temp[i];
            }
            return temp;
        }
    }
    
    /**
     * Your Solution object will be instantiated and called as such:
     * Solution obj = new Solution(nums);
     * int[] param_1 = obj.reset();
     * int[] param_2 = obj.shuffle();
     */
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.