allcoding1
26.9K subscribers
2.2K photos
2 videos
77 files
861 links
Download Telegram
🎯NoBroker is hiring

Role : SDE - Frontend
Experience : 1 - 3 years
CTC : 8 - 12 LPA

Apply now :-
https://hirespoof.com/job/nobroker-software-engineer-frontend/


Telegram:- @allcoding1
👍3
vector<ll> babuswiggyjayega(vector<ll> a, vector<ll> b)
{
    ll n1 = a.size(), n2 = b.size();
    ll i = 0, j = 0, k = 0;
    vector<ll> golu(n1 + n2);
    while (i < n1 && j < n2)
    {
        if (a[i] < b[j])
            golu[k++] = a[i++];
        else
            golu[k++] = b[j++];
    }

    while (i < n1)
        golu[k++] = a[i++];
    while (j < n2)
        golu[k++] = b[j++];
    return golu;
}

Merge 2 Arrays

Telegram:- @allcoding1
👍6🔥1
🎯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