Easy Multiple User Defined Java Solution || beats 100% || Explained!!! 💡
Approach\n- To create two user defined functions that take individual arrays and return the reversed as well as flipped bits array.\n- Loop through each array i
# Approach\n- To create two user defined functions that take individual arrays and return the reversed as well as flipped bits array.\n- Loop through each array in the array of array and pass it to both reverse as well as flip functions.\n- Each of these functions take O(n) time given there are n elements in each array of the given array of arrays.\n- and repeating this for m number of arrays id O(m).\n\n\n# Complexity\n- Time complexity: O(m*n)\n\n- Space complexity:O(1)\n\n# Code\n```\nclass Solution {\n    public int[][] flipAndInvertImage(int[][] image) {\n        for(int i = 0;i<image.length;i++){\n\n            // calling the user defined function reverse for reversal of the array\n\n            image[i] = reverse(image[i]);\n\n            // calling the user define dfunction to flip the bits in the array\n\n            image[i] = flip(image[i]);\n        }\n\n        // returns the original array of arrays as we make changes in it\n\n        return image;\n    }\n\n    // reverse the elements of the array\n\n    // for elements arranged as ---> [0][1][2][3][4]\n                    // [0] <---> [4]\n                    // [1] <---> [3]\n                    // [2] <---> [2]\n\n    public int[] reverse(int[] arr){\n        int ind = arr.length - 1;\n        for(int i = 0;i<arr.length;i++){\n            if(ind >= i){    \n                int temp = arr[i];\n                arr[i] = arr[ind];\n                arr[ind] = temp;\n                ind--;\n            }\n        }\n        return arr;\n    }\n\n    // flip the bits of the array\n\n    // for elements arranged as ---> [0][0][1][0][1]\n            // new array ---> [1][1][0][1][0]\n\n    public int[] flip(int[] arr){\n        for(int i = 0;i<arr.length;i++){\n            if(arr[i] == 0){\n                arr[i] = 1;\n            }else{\n                arr[i] = 0;\n            }\n        }\n        return arr;\n    }\n}\n```
['Array', 'Java']