๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.54K subscribers
5.57K photos
3 videos
95 files
9.8K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
int fun(int node, int parent, vector<vector<int> >&adj, vector<int>&weight, int &maxi)
{
    int sum1 = 0;
    for(auto it:adj[node])
    {
        if(it != parent)
        {
            sum1 += fun(it,node,adj,weight,maxi);
        }
    }

    sum1 = max(sum1,weight[node-1]);
    maxi = max(maxi,sum1);
    return sum1;
}

int findMaximumSum(int tree_nodes, vector<int> tree_from, vector<int> tree_to, vector<int> weight)
{
    int n = tree_nodes;

    vector<vector<int> > adj(n+1);
    for(int i = 0; i<tree_from.size(); i++)
    {
        adj[tree_from[i]].push_back(tree_to[i]);
        adj[tree_to[i]].push_back(tree_from[i]);
    }

    int maxi = -1e9;
    fun(1,-1,adj,weight,maxi);
    return maxi;

}
vector<int> countVisibleTowers(vector<int>& height) {
  int n = height.size();
  vector<int> visible(n, 0);
  stack<int> s;

  for (int i = 0; i < n; ++i) {

    visible[i] += s.size();
    while (!s.empty() && height[s.top()] <= height[i]) {
      s.pop();
    }
    s.push(i);
  }

  while (!s.empty()) s.pop();


  for (int i = n - 1; i >= 0; --i) {

    visible[i] += s.size();
    while (!s.empty() && height[s.top()] <= height[i]) {
      s.pop();
    }
    s.push(i);
  }

  return visible;
}


Rippling โœ…
๐Ÿ‘Ž1
#include <iostream>
using namespace std;
const int MOD = 1000000007;
long countWays(int n) {
long long dp[100001][2] = {0};
dp[1][0] = 1;
   dp[1][1] = 0;
   if(n >= 2) {
       dp[2][0] = 1;
       dp[2][1] = 1;
   }
      for(int i = 3; i <= n; i++) {
     dp[i][0] = (dp[i-1][0] + dp[i-1][1]) % MOD;
    dp[i][1] = dp[i-2][0] % MOD;
   }
     return (dp[n][0] + dp[n][1]) % MOD;
}

int main() {
   int n;
   cin >> n;
   cout << countWays(n) << endl;
   return 0;
}

Vimo โœ…
๐Ÿ‘1๐Ÿ‘Ž1
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string mergePalindrome(string&a,string&b)
{  
    ll n=a.length();
    ll m=b.length();
    unordered_map<char,ll> m1,m2;
    for(char it:a) m1[it]++;
    for(char it:b) m2[it]++;
    string mid="",ans="";
    for (char i='a';i<='z';i++)
    {
        if(m1[i]%2 and m2[i]%2 and mid.length()<=1)  mid=string(2,i);
        if((m1[i]%2 or m2[i]%2) and mid.length()==0) mid=i;
        ans+=string((m1[i]/2+m2[i]/2),i);
    }
    string tt=ans;
    if (mid.length()==2)
    {  
        tt+=mid[0];
        ans+=mid[0];
        sort(begin(ans),end(ans));
        tt=ans+string(rbegin(ans),rend(ans));
    }
    else tt+=mid+string(rbegin(ans),rend(ans));
    return tt;
}
signed main()
{   
        string s,t; cin>>s>>t;
        cout<<solve(s,t);
    return 0;
}

Merging palindromes โœ…
๐Ÿ‘1
#include <bits/stdc++.h>
using namespace std;

#define loop(i, a, n) for (lli i = (a); i < (n); ++i)
#define loopD(i, a, n) for (lli i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define sz(a) ((lli)a.size())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define endl '\n'
#define fastio std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define fi first
#define si second
#define v(a) vector<int>(a)
#define vv(a) vector<vector<int>>(a)
#define present(c, x) ((c).find(x) != (c).end())
#define set_bits __builtin_popcountll
#define MOD 1000000007
#define int long long

typedef long long lli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pll;
typedef pair<int, int> pii;
typedef unordered_map<int, int> umpi;
typedef map<int, int> mpi;
typedef vector<pii> vp;
typedef vector<lli> vll;
typedef vector<vll> vvll;

struct Line {
    int x1, y1, x2, y2;
    bool vertical() const { return x1 == x2; }
    bool horizontal() const { return y1 == y2; }
    bool diagonal() const { return abs(x2 - x1) == abs(y2 - y1); }
};

int N, K;
vector<Line> lines;
map<pair<int, int>, vector<int>> ptsMap;


void add(const Line& line, int idx) {
    int x1 = line.x1, y1 = line.y1;
    int x2 = line.x2, y2 = line.y2;

    if (line.vertical()) {
        int yStart = min(y1, y2);
        int yEnd = max(y1, y2);
        for(int y = yStart; y <= yEnd; y++) {
            ptsMap[{x1, y}].push_back(idx);
        }
    }
    else if (line.horizontal()) {
        int xStart = min(x1, x2);
        int xEnd = max(x1, x2);
        for(int x = xStart; x <= xEnd; x++) {
            ptsMap[{x, y1}].push_back(idx);
        }
    }
    else if (line.diagonal()) {
        int steps = abs(x2 - x1);
        int dx = (x2 - x1) / steps;
        int dy = (y2 - y1) / steps;
        for(int i = 0; i <= steps; i++) {
            int x = x1 + i * dx;
            int y = y1 + i * dy;
            ptsMap[{x, y}].push_back(idx);
        }
    }
}


int ff(int x1, int y1, int x2, int y2) {
    if(x1 == x2) return abs(y1 - y2);
    if(y1 == y2) return abs(x1 - x2);
    if(abs(x1 - x2) == abs(y1 - y2)) return abs(x1 - x2);
    return 0;
}

int solve(const pair<int, int>& pt, const vector<int>& lst) {
    vector<int> d;
    for(auto lIdx : lst) {
        const Line& ln = lines[lIdx];
        bool oneSided = (pt.first == ln.x1 && pt.second == ln.y1) || 
                        (pt.first == ln.x2 && pt.second == ln.y2);
        if(oneSided) {
            int ex = (pt.first == ln.x1 && pt.second == ln.y1) ? ln.x2 : ln.x1;
            int ey = (pt.first == ln.x1 && pt.second == ln.y1) ? ln.y2 : ln.y1;
            d.push_back(ff(pt.first, pt.second, ex, ey));
        }
        else {
            d.push_back(ff(pt.first, pt.second, ln.x1, ln.y1));
            d.push_back(ff(pt.first, pt.second, ln.x2, ln.y2));
        }
    }
    return d.empty() ? 0 : *min_element(d.begin(), d.end());
}


void solve() {
    cin >> N;
    lines.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> lines[i].x1 >> lines[i].y1 >> lines[i].x2 >> lines[i].y2;
        add(lines[i], i);
    }
    cin >> K;

    int total = 0;
    for(auto &[pt, lst] : ptsMap) {
        if(sz(lst) == K) {
            total += solve(pt, lst);
        }
    }
    cout << total << "\n";
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    solve();
    return 0;
}

Magic Stars โœ…
TCS Codevita
Source : ishaan
๐Ÿ‘2