diff --git a/Problem Statement 1/solution1.cpp b/Problem Statement 1/solution1.cpp new file mode 100644 index 0000000..5190edf --- /dev/null +++ b/Problem Statement 1/solution1.cpp @@ -0,0 +1,19 @@ + int getMove(int n){ + for (int i = 1; i < n; i++){ + if (n % i == 0) + return i; + } + return -1; + } + + bool divisorGame(int n) { + vector dp; + dp.push_back(n); + int move = getMove(n), i = 0; + + while (move != -1){ + dp.push_back(dp[i] - move); + move = getMove(dp[++i]); + } + + return dp.size() % 2 == 0; diff --git a/Problem Statement 2/Solution2.cpp b/Problem Statement 2/Solution2.cpp new file mode 100644 index 0000000..51b136f --- /dev/null +++ b/Problem Statement 2/Solution2.cpp @@ -0,0 +1,5 @@ + int countVowelStrings(int n) { + n+=4; + long long sol = n*(n-1)*(n-2)*(n-3)/24; + return sol; + } diff --git a/Problem Statement 3/Solution3.cpp b/Problem Statement 3/Solution3.cpp new file mode 100644 index 0000000..7c02d0a --- /dev/null +++ b/Problem Statement 3/Solution3.cpp @@ -0,0 +1,18 @@ +int solve(vector& arr, int k) { + int n=arr.size(); + vector t(n+1,0); + t[1]=arr[0]; + for(int i=2;i=0;j++) + { int maa=0; + for(int l=1;l<=j && i-l>=0;l++) + maa=max(maa,arr[i-l]); + temp=max(temp,t[i-j]+maa*j); + t[i]=temp; + } + } + return t[n]; + }