diff --git a/2024 Daily Challenges/February 2024 Challenges/FEB09_Largest divisible subset.cpp b/2024 Daily Challenges/February 2024 Challenges/FEB09_Largest divisible subset.cpp new file mode 100644 index 0000000..f82c1cf --- /dev/null +++ b/2024 Daily Challenges/February 2024 Challenges/FEB09_Largest divisible subset.cpp @@ -0,0 +1,30 @@ +class Solution { +public: + vector largestDivisibleSubset(vector& nums) { + int n=(int)nums.size(), maxi=1, num=-1; + vectorv; + sort(nums.begin(), nums.end()); + vectordp(n, 1); + for(int i=1; i=0; i--){ + if(maxi==dp[i] && (num==-1 || !(num%nums[i]))){ + v.push_back(nums[i]); + maxi--; + num=nums[i]; + } + } + return v; + } +}; + +// Time Complexity- O(n^2) +//Space Complexity-o(n) \ No newline at end of file