๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.6K subscribers
5.59K photos
3 videos
95 files
10.1K 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
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bool prime[100005];
int dp[100005];
ll answer;
bool visited[100005];
vector<int> adjacent[100005];

void dfs1(int u) {
visited[u] = true;
int sum = prime[u] ? 0 : 1;
for (int i = 0; i < adjacent[u].size(); i++) {
int v = adjacent[u][i];

if (!visited[v]) {
dfs1(v);
sum += dp[v];
}
}

dp[u] = sum;

if (prime[u]) dp[u] = 0;
}

void dfs2(int u, int p, int dv) {
visited[u] = true;

if (prime[u]) {
vector<ll> pp;
ll sum = dv;
pp.push_back(dv);
for (int i = 0; i < adjacent[u].size(); i++) {
int v = adjacent[u][i];

if (!visited[v] && v != p) {
dfs2(v, u, 0);
pp.push_back(dp[v]);
sum += dp[v];
}
}

ll val = 0;
for (int i = 0; i < pp.size(); i++) {
val += (sum - pp[i]) * pp[i];
}

val /= 2;
answer += val;
answer += sum;
} else {
for (int i = 0; i < adjacent[u].size(); i++) {
int v = adjacent[u][i];

if (!visited[v] && v != p) {
dfs2(v, u, dv + dp[u] - dp[v]);
}
}
}
}

void Sieve() {
for (int i = 1; i <= 100000; i++) {
prime[i] = true;
}

prime[1] = false;

for (int i = 2; i * i <= 100000; i++) {
if (prime[i]) {
for (int j = i * i; j <= 100000; j += i) {
prime[j] = false;
}
}
}
}

int main() {
Sieve();

int n;
cin >> n;
assert(1 <= n && n <= 100000);

for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
assert(1 <= u && u <= n);
assert(1 <= v && v <= n);

adjacent[u].push_back(v);
adjacent[v].push_back(u);
}

dfs1(1);
for (int i = 1; i <= n; i++) visited[i] = false;

dfs2(1, 0, 0);

cout << answer << endl;
}

Sprinklr โœ…
(Search Engine)
#include <bits/stdc++.h>
using namespace std;

int main ()
{
int n;
cin >> n;
vector<int64_t> min_cost(n+2, 0x3f3f3f3f3f3f3f3f);
min_cost[0] = 0;
vector<int> range(n+2), cost(n+2);
for (int i = 1; i <= n+1; i++) {
cin >> range[i];
}
for (int i = 1; i <= n+1; i++) {
cin >> cost[i];
}
for (int i = 1; i <= n+1; i++) {
if (range[i] == 0) continue;

int nxt = min(i + range[i], n+1);
int prev = max(i - range[i] - 1, 0);
int64_t cprev = cost[prev];
for (int j = prev+1; j <= nxt; j++) {
min_cost[j] = min(min_cost[j], min_cost[prev] + cost[i]);
}
}
cout << ((min_cost[n+1] < 0x3f3f3f3f3f3f3f3f) ? min_cost[n+1]: -1) << "\n";
}

Garden
Intuit โœ…
๐Ÿ‘1
public static int find(int[] arr) {
// Sort the array in ascending order
Arrays.sort(arr);
HashSet<Double> hm=new HashSet<>();

int n = arr.length;
int count = 0;
int left = 0;
int right = n - 1;

while (left < right) {

double avgMaxMin = (arr[left] + arr[right]) / 2.0;

hm.add(avgMaxMin);

left++;
right--;
}

return hm.size();
}

Amazon OAโœ…
    public static String lexicographicallyMaxString(String inputStr) {
        char[] chars = inputStr.toCharArray();
        int n = chars.length;
        HashSet<Character> c=new HashSet<>();

    
        Map<Character, Integer> charCount = new HashMap<>();
        for (char ch : chars) {
            charCount.put(ch, charCount.getOrDefault(ch, 0) + 1);
        }

      
        PriorityQueue<Character> pq = new PriorityQueue<>((a, b) -> a-b);
        for (char ch : charCount.keySet()) {
            pq.add(ch);
            c.add(ch);
        }

      
        StringBuilder sb = new StringBuilder();
        while (!pq.isEmpty()) {
            char currentChar = pq.poll();
            if(c.contains(currentChar)){
            sb.append(currentChar);
            c.remove(currentChar);
            }
        }

        return sb.toString();
    }


Modify the string โœ…
Cisco Interview Experience :

1)First introduction
2)Then she asked about course like i have done cisco ccna course that
3)Then about web dev internship
4)College Project Explain
5)About python
6)Why python
7)She gave a task like CAT BAT PAT DAT
output should be like

["CA", "BA", "PA", "DA"]
8)Then 2 questions about dependency
9)Global and local variables
10)The she gave me 2 strings and asked me how to print them in one line
11)Without using concat
12)OOPS
13)Different between python and java
14)Reverse of a number
15)Swapping
16)Why reactjs
17)API
18)Backend coding
19)If u are from ECE then they will ask logic of code
Any Questions
๐Ÿ‘2