diff --git a/Leetcode/0952-word-subsets/index.md b/Leetcode/0952-word-subsets/index.md
index 1a36caea..c7866ee7 100644
--- a/Leetcode/0952-word-subsets/index.md
+++ b/Leetcode/0952-word-subsets/index.md
@@ -80,7 +80,39 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ vector wordSubsets(vector& words1, vector& words2) {
+ vector ans;
+ vector maxFreq(26, 0);
+ for (const string& word : words2) {
+ vector freq(26, 0);
+ for (char c : word) {
+ freq[c - 'a']++;
+ }
+ for (int i = 0; i < 26; i++) {
+ maxFreq[i] = max(maxFreq[i], freq[i]);
+ }
+ }
+ for (const string& word : words1) {
+ vector freq(26, 0);
+ for (char c : word) {
+ freq[c - 'a']++;
+ }
+ bool isSubset = true;
+ for (int i = 0; i < 26; i++) {
+ if (freq[i] < maxFreq[i]) {
+ isSubset = false;
+ break;
+ }
+ }
+ if (isSubset) {
+ ans.push_back(word);
+ }
+ }
+ return ans;
+ }
+};
```
diff --git a/Leetcode/1510-find-lucky-integer-in-an-array/index.md b/Leetcode/1510-find-lucky-integer-in-an-array/index.md
index 800f3147..ddaab6f7 100644
--- a/Leetcode/1510-find-lucky-integer-in-an-array/index.md
+++ b/Leetcode/1510-find-lucky-integer-in-an-array/index.md
@@ -69,7 +69,20 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ int findLucky(vector& arr) {
+ map mpp;
+ for(auto &it : arr) mpp[it]++;
+ int res = -1;
+ for(auto it : mpp){
+ if(it.first == it.second){
+ res = max(res, it.first);
+ }
+ }
+ return res;
+ }
+};
```
diff --git a/Leetcode/1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/index.md b/Leetcode/1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/index.md
index 7a829783..fd912c73 100644
--- a/Leetcode/1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/index.md
+++ b/Leetcode/1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/index.md
@@ -97,7 +97,29 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+private:
+ void solve(string &curr, vector &res, int n){
+ if(curr.size() == n){
+ res.push_back(curr);
+ return;
+ }
+ for(char ch = 'a'; ch <= 'c'; ch++){
+ if(!curr.empty() && curr.back() == ch) continue;
+ curr.push_back(ch);
+ solve(curr, res, n);
+ curr.pop_back();
+ }
+ }
+public:
+ string getHappyString(int n, int k) {
+ string curr = "";
+ vector res;
+ solve(curr, res, n);
+ if(res.size() < k) return "";
+ return res[k - 1];
+ }
+};
```
diff --git a/Leetcode/1529-max-difference-you-can-get-from-changing-an-integer/index.md b/Leetcode/1529-max-difference-you-can-get-from-changing-an-integer/index.md
index a37700a1..1870b5d5 100644
--- a/Leetcode/1529-max-difference-you-can-get-from-changing-an-integer/index.md
+++ b/Leetcode/1529-max-difference-you-can-get-from-changing-an-integer/index.md
@@ -100,7 +100,41 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ int maxDiff(int num) {
+ auto replace = [](string& s, char x, char y) {
+ for (char& digit : s) {
+ if (digit == x) {
+ digit = y;
+ }
+ }
+ };
+ string min_num = to_string(num);
+ string max_num = to_string(num);
+ for (char digit : max_num) {
+ if (digit != '9') {
+ replace(max_num, digit, '9');
+ break;
+ }
+ }
+ for (int i = 0; i < min_num.size(); ++i) {
+ char digit = min_num[i];
+ if (i == 0) {
+ if (digit != '1') {
+ replace(min_num, digit, '1');
+ break;
+ }
+ } else {
+ if (digit != '0' && digit != min_num[0]) {
+ replace(min_num, digit, '0');
+ break;
+ }
+ }
+ }
+ return stoi(max_num) - stoi(min_num);
+ }
+};
```
diff --git a/Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md b/Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md
index cc3d37e7..309a6546 100644
--- a/Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md
+++ b/Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md
@@ -88,7 +88,27 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ int maxScore(vector& cardPoints, int k) {
+ int n = cardPoints.size();
+ int lsum = 0;
+ int rsum = 0;
+ int maxsum = 0;
+ for(int i = 0 ; i < k ; i++){
+ lsum += cardPoints[i];
+ }
+ maxsum = lsum;
+ int right = n - 1;
+ for(int i = k - 1 ; i >= 0 ; i--){
+ lsum -= cardPoints[i];
+ rsum += cardPoints[right];
+ maxsum = max(maxsum , lsum + rsum);
+ right--;
+ }
+ return maxsum;
+ }
+};
```
diff --git a/Leetcode/1558-course-schedule-iv/index.md b/Leetcode/1558-course-schedule-iv/index.md
index 2a781c56..8e975a08 100644
--- a/Leetcode/1558-course-schedule-iv/index.md
+++ b/Leetcode/1558-course-schedule-iv/index.md
@@ -111,7 +111,31 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ vector checkIfPrerequisite(int numCourses, vector>& prerequisites, vector>& queries) {
+ map> reachable;
+ for(auto it : prerequisites){
+ reachable[it[1]].insert(it[0]);
+ }
+ int n = numCourses;
+ for(int i = 0 ; i < n; i++){
+ for(int j = 0 ; j < n ; j++){
+ if(reachable[j].count(i)){
+ reachable[j].insert(reachable[i].begin() , reachable[i].end());
+ }
+ }
+ }
+ vector res;
+ for(int i = 0 ; i < queries.size() ; i++){
+ if(reachable[queries[i][1]].count(queries[i][0])){
+ res.push_back(true);
+ }
+ else res.push_back(false);
+ }
+ return res;
+ }
+};
```
diff --git a/Leetcode/1561-rearrange-words-in-a-sentence/index.md b/Leetcode/1561-rearrange-words-in-a-sentence/index.md
index 9dda9003..69e3b6c4 100644
--- a/Leetcode/1561-rearrange-words-in-a-sentence/index.md
+++ b/Leetcode/1561-rearrange-words-in-a-sentence/index.md
@@ -133,7 +133,23 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ string arrangeWords(string text) {
+ text[0] = text[0] - 'A' + 'a';
+ map> mp;
+ stringstream ss(text);
+ string word;
+ while (ss >> word) mp[word.size()].push_back(word);
+ string ans;
+ for (auto &x : mp) {
+ for (string &v : x.second) ans += v + " ";
+ }
+ ans.pop_back();
+ ans[0] = toupper(ans[0]);
+ return ans;
+ }
+};
```
diff --git a/Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md b/Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md
index 371b1e0e..ef69cfb7 100644
--- a/Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md
+++ b/Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md
@@ -80,7 +80,23 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ int isPrefixOfWord(string sentence, string searchWord) {
+ int idx = 1;
+ int start = 0;
+ for (int i = 0; i <= sentence.size(); i++){
+ if (sentence[i] == ' ' ||i == sentence.size()){
+ string prefix = sentence.substr(start, searchWord.size());
+ if (searchWord == prefix)
+ return idx;
+ start = 1 + i;
+ idx++;
+ }
+ }
+ return -1;
+ }
+};
```
diff --git a/Leetcode/1570-final-prices-with-a-special-discount-in-a-shop/index.md b/Leetcode/1570-final-prices-with-a-special-discount-in-a-shop/index.md
index d4d07cbd..38c48899 100644
--- a/Leetcode/1570-final-prices-with-a-special-discount-in-a-shop/index.md
+++ b/Leetcode/1570-final-prices-with-a-special-discount-in-a-shop/index.md
@@ -79,7 +79,26 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ vector finalPrices(vector& prices) {
+ int n = prices.size();
+ stack> st;
+ vector res(n, 0);
+ for (int i = n - 1; i >= 0; i--) {
+ while (!st.empty() && st.top().first > prices[i]) {
+ st.pop();
+ }
+ if (!st.empty()) {
+ res[i] = prices[i] - st.top().first;
+ } else {
+ res[i] = prices[i];
+ }
+ st.push({prices[i], i});
+ }
+ return res;
+ }
+};
```
diff --git a/Leetcode/1585-the-kth-factor-of-n/index.md b/Leetcode/1585-the-kth-factor-of-n/index.md
index 384c3693..53ce1b27 100644
--- a/Leetcode/1585-the-kth-factor-of-n/index.md
+++ b/Leetcode/1585-the-kth-factor-of-n/index.md
@@ -75,7 +75,21 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ int kthFactor(int n, int k) {
+ vector factors;
+ for(int i = 1; i * i <= n ; i++){
+ if(n % i == 0){
+ factors.push_back(i);
+ if(n / i != i) factors.push_back(n / i);
+ }
+ }
+ sort(factors.begin(), factors.end());
+ if(k > factors.size()) return -1;
+ return factors[k - 1];
+ }
+};
```
diff --git a/Leetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.md b/Leetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.md
index db6afe82..bc8a4bca 100644
--- a/Leetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.md
+++ b/Leetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.md
@@ -79,7 +79,31 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+public:
+ const int mod=1000000007;
+ int numSubseq(vector& nums, int target) {
+ int n = nums.size();
+ sort(nums.begin() , nums.end());
+ vector noOfsub(n + 1 , 1);
+ for(int i = 1 ; i <= n ; i++){
+ noOfsub[i] = (2 * noOfsub[i - 1]) % mod;
+ }
+ int i = 0;
+ int j = n - 1;
+ int res = 0;
+ while(i <= j){
+ if(nums[j] + nums[i] <= target){
+ res = (res + noOfsub[j - i]) % mod;
+ i++;
+ }
+ else{
+ j--;
+ }
+ }
+ return res;
+ }
+};
```
diff --git a/Leetcode/1628-count-submatrices-with-all-ones/index.md b/Leetcode/1628-count-submatrices-with-all-ones/index.md
index 687098ca..3f6b0f5a 100644
--- a/Leetcode/1628-count-submatrices-with-all-ones/index.md
+++ b/Leetcode/1628-count-submatrices-with-all-ones/index.md
@@ -136,7 +136,38 @@ class Solution {
```cpp
-// Add your C++ solution here
+class Solution {
+private:
+ int findRes(vector& temp){
+ int res = 0;
+ int consec = 0;
+ for(auto it : temp){
+ if(it == 0){
+ consec = 0;
+ } else {
+ consec++;
+ }
+ res += consec;
+ }
+ return res;
+ }
+public:
+ int numSubmat(vector>& mat) {
+ int n = mat.size();
+ int m = mat[0].size();
+ int res = 0;
+ for(int srow = 0; srow < n; srow++){
+ vector v(m, 1);
+ for(int erow = srow; erow < n; erow++){
+ for(int col = 0; col < m; col++){
+ v[col] = v[col] & mat[erow][col];
+ }
+ res += findRes(v);
+ }
+ }
+ return res;
+ }
+};
```