๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.61K photos
3 videos
95 files
10.6K 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
Company Name : Collins
Role : Internship at Collins and Prat and Whitney
Batch : 2025 female passouts from mechanical and allied branches only (Aerospace, Mechatronics, Industrial Engineering Management & Automobile)
Prizes worth 1 Lakh and Samsung Tab too.
Link : https://bit.ly/CollinsInternship

Share it with your core branch friends.
#include <bits/stdc++.h>
using namespace std;

bool wordBreak(string s, vector<string>& wordDict) {
    unordered_set<string> dict(wordDict.begin(), wordDict.end());
    vector<bool> dp(s.size() + 1, false);
    dp[0] = true;
   
    for (int i = 1; i <= s.size(); ++i) {
        for (int j = i - 1; j >= 0; --j) {
            if (dp[j]) {
                string word = s.substr(j, i - j);
                if (dict.find(word) != dict.end()) {
                    dp[i] = true;
                    break;
                }
            }
        }
    }
    return dp[s.size()];
}

int main() {
    string s = "penappleapple";
    vector<string> wordDict = {"apple","pen"};
    cout << (wordBreak(s, wordDict) ? "true" : "false") << endl;
    return 0;
}

Kitty in horror house
Salesforce โœ…
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int getSmallestArea(vector<vector<int>>& grid) {
    int rows = grid.size();
    if (rows == 0) return 0;
    int cols = grid[0].size();
    if (cols == 0) return 0;

    set<int> rowsSet, colsSet;

    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            if (grid[i][j] == 1) {
                rowsSet.insert(i);
                colsSet.insert(j);
            }
        }
    }

    int width = colsSet.empty() ? 0 : *colsSet.rbegin() - *colsSet.begin() + 1;
    int height = rowsSet.empty() ? 0 : *rowsSet.rbegin() - *rowsSet.begin() + 1;

    return width * height;
}

Salesforce โœ…
Get smallest Area
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
int closestToTarget(vector<int> oxygenLevels, int target) {     int n = oxygenLevels.size();     int minDiff = abs(oxygenLevels[0] - target); // Initialize the minimum difference with the first oxygen level     // Iterate through the oxygen levels to findโ€ฆ
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int closestToTarget(vector<int>& oxygenLevels, int target) {
    int n = oxygenLevels.size();
    int minDiff = INT_MAX;

    for (int i = 0; i < n; ++i) {
        int andValue = oxygenLevels[i];

        for (int j = i; j < n; ++j) {
            andValue &= oxygenLevels[j];

            minDiff = min(minDiff, abs(andValue - target));
            if (andValue == 0) break;
        }
    }

    return minDiff;
}

Optimum oxygen
Salesforce โœ…
#include <unordered_map>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

class designCache {
public:
    class Node {
    public:
        int key;
        int val;
        Node* prev;
        Node* next;

        Node(int key, int val) {
            this->key = key;
            this->val = val;
        }
    };

    Node* head = new Node(-1, -1);
    Node* tail = new Node(-1, -1);

    int cap;
    unordered_map<int, Node*> m;

    designCache(int capacity) {
        cap = capacity;
        head->next = tail;
        tail->prev = head;
    }

    void addNode(Node* newnode) {
        Node* temp = head->next;

        newnode->next = temp;
        newnode->prev = head;

        head->next = newnode;
        temp->prev = newnode;
    }

    void deleteNode(Node* delnode) {
        Node* prevv = delnode->prev;
        Node* nextt = delnode->next;

        prevv->next = nextt;
        nextt->prev = prevv;
    }

    int get(int key) {
        if (m.find(key) != m.end()) {
            Node* resNode = m[key];
            int ans = resNode->val;

            m.erase(key);
            deleteNode(resNode);
            addNode(resNode);

            m[key] = head->next;
            return ans;
        }
        return -1;
    }

    void put(int key, int value) {
        if (m.find(key) != m.end()) {
            Node* curr = m[key];
            m.erase(key);
            deleteNode(curr);
        }

        if (m.size() == cap) {
            m.erase(tail->prev->key);
            deleteNode(tail->prev);
        }

        addNode(new Node(key, value));
        m[key] = head->next;
    }
};

int main() {
    string attribs, attrib;
    getline(cin, attribs);
    stringstream ss(attribs);
    int capacity, key, val;
    cin >> capacity;
    designCache obj(capacity);
    while (getline(ss, attrib, ' ')) {
        if (attrib == "put") {
            cin >> key >> val;
            obj.put(key, val);
            cout << "null ";
        } else if (attrib == "get") {
            cin >> key;
            val = obj.get(key);
            cout << val << " ";
        }
    }
    return 0;
}.

Design a cache โœ…
static int maximize(int arr[], int n)
    {
        int prefixSum[] = new int[n];
       
        int totalSum = 0;
   
    
        int maxPrefixSum = 0;
       
        for (int i = 0; i < n; i++)
        {
            prefixSum[i] = maxPrefixSum ;
           
            maxPrefixSum += arr[i];
            totalSum += arr[i];
           
            maxPrefixSum = Math.max(maxPrefixSum, -totalSum);
        }
       
        int maxSum = Math.max(totalSum, maxPrefixSum);
       
        int suffixSum = 0;
        for (int i = n - 1; i >= 0; --i)
        {
            suffixSum -= arr[i];
   
 
            maxSum = Math.max(maxSum, suffixSum + prefixSum[i]);
        }
       
        return maxSum;
    }.  add this if size == 1:
return arr[0]

DE Shaw โœ…
int solve(vector<int>& A, int K) {
    int i = 0, j;
    for (j = 0; j < A.size(); ++j) {
        if (A[j] == 0) K--;
        if (K < 0 && A[i++] == 0) K++;
    }
    return j - i;
}

Power Array โœ…
#include <iostream>
#include <vector>
using namespace std;

const int MOD = 1e9 + 7;

int F(int i, int k, int n, vector<int> &level, vector<int> &dp) {
    if (i == n) return 1;
    if (dp[i] != -1) return dp[i];
    int ans = 0, odds = 0;
    vector<int> hash(n + 10, 0);
    for (int j = i; j < n; j++) {
        if (++hash[level[j]] % 2 == 0) odds -= 1;
        else odds += 1;
        if (odds <= k) {
            ans = (ans + F(j + 1, k, n, level, dp)) % MOD;
        }
    }
    return dp[i] = ans;
}

int countValidPartitions(vector<int> level, int k) {
    int n = level.size();
    vector<int> dp(n, -1);
    return F(0, k, n, level, dp);
}

DE Shaw โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int getMaxMedian(vector<int> lower_bound, vector<int> upper_bound, long int max_sum) {
    int n = lower_bound.size();
    long long curr_sum = 0;
    for (int i = 0; i < n; ++i) {
        curr_sum += lower_bound[i] + upper_bound[i];
    }
    int num_elements = 2 * n;
    long long target_sum = curr_sum + max_sum;
    sort(upper_bound.begin(), upper_bound.end());
    int median_index = num_elements / 2;
    int left = 1, right = INT_MAX;
    while (left <= right) {
        int mid = left + (right - left) / 2;
        long long sum = 0;
        for (int i = 0; i < n; ++i) {
            if (upper_bound[i] <= mid) {
                sum += upper_bound[i];
            } else {
                sum += mid;
            }
        }
        if (sum <= target_sum) {
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }
    return right;
}

int main() {
    int n;
    cin >> n;
    vector<int> lower_bound(n);
    vector<int> upper_bound(n);
    for (int i = 0; i < n; ++i) {
        cin >> lower_bound[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> upper_bound[i];
    }
    long int max_sum;
    cin >> max_sum;
    int max_median = getMaxMedian(lower_bound, upper_bound, max_sum);
    cout << max_median << endl;
    return 0;
}

DE Shaw โœ…
๐Ÿ‘1
#include <iostream>
#include <vector>

using namespace std;

int findSingleSock(vector<int>& socks) {
    int result = 0;
    for (int num : socks) {
        result ^= num;
    }
    return result;
}

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

    vector<int> socks(N);
    for (int i = 0; i < N; ++i) {
        cin >> socks[i];
    }

    int singleSock = findSingleSock(socks);
    cout << singleSock << endl;

    return 0;
}

Missing sock โœ…
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

    vector<pair<ll, ll>> t(N);
    ll tc1 = 0;

    for (int i = 0; i < N; ++i) {
        cin >> t[i].first >> t[i].second;
        tc1 += t[i].first;
    }

    sort(t.begin(), t.end(), [](const pair<ll, ll>& a, const pair<ll, ll>& b) {
        return a.first * 2 + a.second > b.first * 2 + b.second;
    });

    ll tc2 = 0;
    int m = 0;

    for (int i = 0; i < N; ++i) {
        if (tc2 > tc1) {
            break;
        }
        tc1 -= t[i].first;
        tc2 += t[i].first + t[i].second;
        m++;
    }

    cout << m << endl;

    return 0;
}

Flipkart โœ…
#define ll long long
#define MAXN 100005
#define INF 1000000007

using namespace std;

void removeDuplicates(vector<string>& words) {
    unordered_set<string> seen;
    vector<string> result;

    for (const string& word : words) {
        if (seen.find(word) == seen.end()) {
            result.push_back(word);
            seen.insert(word);
        }
    }

    for (const string& word : result) {
        cout << word << " ";
    }
    cout << "\n";
}

int main() {
    ll t;
    cin >> t;

    while (t--) {
        ll n;
        cin >> n;

        vector<string> words(n);
        for (ll i = 0; i < n; i++) {
            cin >> words[i];
        }

        removeDuplicates(words);
    }

    return 0;
}

Flipkart โœ…
๐Ÿ‘1