Using Recursion Java| Divide And Conquer| O(log n) time
We know that the array length is power of 2. We can repeatedly divide the array into half.\n- But for each divided subarray, we have to find its min or max elem
- We know that the array length is power of 2. We can repeatedly divide the array into half.\n- But for each divided subarray, we have to find its min or max element.\n\nHow do we know if we have to find min or max value?\nFor that we will track a variable `min`.\n-- If value of `min` is `1`, we have to find the minimum value of current subarray.\n-- If value of `min` is `2`, we have to find the maximum value of current subarray.\n\nThe trick is that,\nWe have to recursively find the middle of the array.\nFrom the left subarray, we have to find the min, this can be indicated by passing `1` in recursion for variable `min`\nFrom the right subarray, we have to find the max, this can be indicated by passing `2` in recursion for variable `min`\nAt the last, \nwe will find the min of left and right subarray values based on value of variable `min`.\n```\nclass Solution {\n    public int minMaxGame(int[] nums) {\n        int left = 0;\n        int right = nums.length - 1;\n        return recurMinMax(nums, left, right,1);\n        \n        \n        \n    }\n    public int recurMinMax(int[] nums, int left, int right,int min){\n        if(right - left == 0)\n            return nums[right];\n        int mid = (left+ right)/2;\n        int minE = recurMinMax(nums,left,mid,1);\n        int maxE = recurMinMax(nums,mid+1,right,2);\n        \n        if(min == 1){\n            return Math.min(minE, maxE);\n\n        }\n        else return Math.max(minE,maxE);\n        \n    }\n}\n```
[]