allcoding1
26.9K subscribers
2.2K photos
2 videos
77 files
860 links
Download Telegram
🎯Zoho Is Hiring

Role : Software Developer
Qualification:- any
Batch:- any
Location : Chennai

Apply Now:- www.allcoding1.com

Telegram:- @allcoding1
👍2🥰1
📌IT learning courses
📌All programing courses
📌Abdul bari courses
📌Ashok IT

100 rupees

Contact:- @meterials_available
2
promotions

@Priya_i
👍2
Removable subarrays
Hackwithinfy
@allcoding1
👍1
Gas Station
Hackwithinfy
@allcoding1
Maximum Count
Hackwithinfy
@allcoding1
👍1
Send questions
Copy ur question and past you get Answer
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

const int MOD = 1e9 + 7;

vector<vector<int>> tree;
vector<int> a;
unordered_map<int, int> countMap;

bool checkPalindrome(unordered_map<int, int>& countMap) {
int oddCount = 0;
for (auto& it : countMap) {
if (it.second % 2 != 0) oddCount++;
if (oddCount > 1) return false;
}
return true;
}

int dfs(int node) {
int ans = 0;
countMap[a[node]]++;

if (checkPalindrome(countMap)) {
ans = 1;
}

for (auto& child : tree[node]) {
ans += dfs(child);
ans %= MOD;
}

countMap[a[node]]--; // Backtrack to remove the current node's count
return ans;
}

int main() {
int n;
cin >> n;

tree.resize(n + 1);
a.resize(n + 1);
vector<int> par(n + 1);

for (int i = 2; i <= n; i++) {
cin >> par[i];
tree[par[i]].push_back(i);
}

for (int i = 1; i <= n; i++) {
cin >> a[i];
}

int ans = dfs(1);
cout << ans << endl;

return 0;
}



c++

Palindromic subtrees

HackWithInfy

@allcoding1
👍2
#include <iostream>
#include <string>

using namespace std;

bool isGoodString(string s) {
    int count = 0;
    for (char c : s) {
        if (c == 'a') {
            count++;
        } else {
            count--;
        }
        if (count < 0) {
            return false;
        }
    }
    return count == 0;
}

int main() {
    string s = "aaabbbaaa";
    cout << "Is the string good? " << (isGoodString(s) ? "Yes" : "No") << endl;
    return 0;
}

Count Good Triples
C++
HackWithInfy

@allcoding1
👍2
Here's the C++ code to solve the problem:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int settleAccounts(vector<int> A) {
int sum = 0;
for (int num : A) {
sum += num;
}

return -sum;
}

int main() {
int N;
cin &gt;&gt; N;

vector<int> A(N);
for (int i = 0; i &lt; N; i++) {
cin &gt;&gt; A[i];
}

int result = settleAccounts(A);
cout &lt;&lt; result &lt;&lt; endl;

return 0;
}

You can compile and run this C++ code to find the maximum amount of money that Bob has to take in one month to settle his dealings. Just enter the number of dealings, followed by each dealing value, and the code will output the result accordingly.</int></int></algorithm></vector></iostream>