From a0d9d742f9967570f5c89c5e9c6fa078abc7a830 Mon Sep 17 00:00:00 2001 From: Nabil Salah Date: Sat, 10 Feb 2024 01:50:49 +0200 Subject: [PATCH] solve feb09 problem --- .../FEB09_Largest divisible subset.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 2024 Daily Challenges/February 2024 Challenges/FEB09_Largest divisible subset.cpp 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