In case if question was size of subsequence to be removed instead of subarray.
In case someone is curious and wanted to know what happens if question was size of subsequence to be removed instead of subarray.\nHere you go :\n\nYou can took
In case someone is curious and wanted to know what happens if question was size of subsequence to be removed instead of subarray.\nHere you go :\n\nYou can took it as typical knapsack problem where in each recursive call , our aim is to make our remainder equals to zero so that at the end we will have remainder ==0 when divided by p.\n\n```\nint getmyans(vector<int>& nums,int mod,int i,int p)\n    {\n        if(nums.size()==i){\n            \n            if(mod==0)\n                return 0;\n            else\n                return 1000008; //just a max value to be returned don\'t take number too seriously!\n        }\n        \n        int ans1=1000008,ans2=1000008;\n        \n        //i am taking this element\n        int M=nums[i]%p;\n        if(M>mod)\n        {\n            ans1=getmyans(nums,p-(M-mod),i+1,p);\n        }\n        else if(M<mod)\n        {\n            ans1=getmyans(nums,(mod-M),i+1,p);\n        }\n        else{\n            ans1=getmyans(nums,0,i+1,p); \n        }\n        \n        //i am not taking it\n        ans2=getmyans(nums,mod,i+1,p)+1;\n        \n        return min(ans2,ans1);\n    }\n    \n    int minSubarray(vector<int>& nums, int p) {\n        \n        int ans=getmyans(nums,0,0,p);\n        \n        if(ans==nums.size()) //means my function have removed all elements\n            return -1;\n        else\n            return ans;\n    }\n```\n\n
[]