๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.59K photos
3 videos
95 files
10.2K 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>
using namespace std;
bool prime(int num)
{
    if (num <= 1)
        return false;

    for (int i = 2; i * i <= num; ++i)
    {
        if (num % i == 0)
            return false;
    }

    return true;
}
int main()
{
    int l, r;
    cin >> l >> r;
    int ans = 0;
    for (int i = l; i <= r; i++)
    {
        if (prime(abs(i)))
        {
            ans += i;
        }
    }

    cout << ans;
    return 0;
}

TechM Campus 2024

SumPrime
Python โœ…
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    cout << arr[n - 2] + arr[n - 1];

    return 0;
}

Tech Mahindra โœ…
#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    map<char, int> m;
    for (int i = 0; i < s.size(); i++)
    {
        m[s[i]]++;
    }
    for (auto x : m)
    {
        if (x.second == 1)
            ans++;
    }
    cout << ans;
    return 0;
}

Tech Mahindra
C++โœ…
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = n; i < s.size() + n; i++)
    {
        cout << s[i % s.size()];
    }
    return 0;
}
C++โœ…
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[][] arr = new int[N][N];

        scanner.nextLine();
        for (int i = 0; i < N; i++) {
            String[] line = scanner.nextLine().split("#");
            for (int j = 0; j < N; j++) {
                arr[i][j] = Integer.parseInt(line[j]);
            }
        }

        int maxMin = -1;
        List<String> positions = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                int minVal = arr[i][j];
                for (int x = Math.max(i - 1, 0); x <= Math.min(i + 1, N - 1); x++) {
                    for (int y = Math.max(j - 1, 0); y <= Math.min(j + 1, N - 1); y++) {
                        minVal = Math.min(minVal, arr[x][y]);
                    }
                }
                if (minVal > maxMin) {
                    maxMin = minVal;
                    positions.clear();
                    positions.add((i + 1) + "#" + (j + 1));
                } else if (minVal == maxMin) {
                    positions.add((i + 1) + "#" + (j + 1));
                }
            }
        }

        for(String position : positions) {
            System.out.println(position);
        }
    }
}

Game Centre
Java โœ…
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int even = 0, odd = 0;
    while (n > 0)
    {
        if ((n % 10) % 2 == 0)
            even += n % 10;
        else
            odd += n % 10;
        n = n / 10;
    }
    cout << even * odd;
}

C++โœ…
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int k;
    cin >> k;
    sort(arr, arr + n);
    cout << arr[k - 1];
}

C++โœ…
vvl tree;
vector<bool> todo, good;

void dfs(int v, int p = -1) {
    for (int u : tree[v]) {
        if (u != p) {
            dfs(u, v);
            if (todo[u]) {
                todo[v] = true;
            }
            if (good[u]) {
                good[v] = true;
            }
        }
    }
}

long long findMinimumPathLength(ll n, vvl edges, vll visitNodes) {

    tree = vector<vector<long long>>(n);
    todo = vector<bool>(n);
    good = vector<bool>(n);

    for(long long i = 0; i < edges.size(); i++) {
        tree[edges[i][0] - 1].push_back(edges[i][1] - 1);
        tree[edges[i][1] - 1].push_back(edges[i][0] - 1);
    }

    for(long long i = 0; i < visitNodes.size(); i++) {
        todo[visitNodes[i] - 1] = true;
    }
    good[n - 1] = true;

    dfs(0);
    long long ans = 0;

    for(long long i = 0; i < n; i++) {
        if(i == 0) continue;
        if(good[i]) {
            ans++;
        }
        else if(todo[i]) {
            ans += 2;
        }
    }

    return ans;
}

Nodes in a tree
def find_nearest_cities_3(x_cord, y_cord, city, query_cities):
   
    def distance(x_y1, x_y2):
        x1, y1 = x_y1
        x2, y2 = x_y2
        return abs(x2-x1) + abs(y2-y1)
       
    def b_search_smallest(coord_city_list, target_coord, target_city):
        start, end = 0, len(coord_city_list)-1
        while(start<end):
            mid = start + (end - start)//2
            if coord_city_list[mid][0]>=target_coord:
                end = mid
            else:
                start = mid+1
        returning_city  = coord_city_list[start][1]
        if returning_city == query_city:
            dis_around_query = float('inf')
            if start>0:
                dis_around_query = coord_city_list[start-1][0]
                returning_city =coord_city_list[start-1][1]
            if start<len(coord_city_list)-1 and coord_city_list[start+1][0]<=dis_around_query:
                    dis_around_query = coord_city_list[start+1][0]
                    returning_city =coord_city_list[start+1][1]
        return returning_city
               
   
    x_map, y_map, c_map = defaultdict(list), defaultdict(list), defaultdict()
    for c, x, y in zip(city, x_cord, y_cord):
        x_map[x].append((y, c))
        y_map[y].append((x, c))
        c_map[c]= (x, y)
   
    for k in x_map.keys():
        x_map[k].sort()
        y_map[k].sort()
   
    # print(x_map)
    # print(y_map)
    # print(c_map)
    res = []
    for query_city in query_cities:
        if query_city not in c_map:
            res.append(None)
        else:
            query_x, query_y = c_map[query_city]
            city_near_x = b_search_smallest(x_map[query_x], query_y, query_city)
            city_near_y = b_search_smallest(y_map[query_y], query_x, query_city)
            if city_near_x == query_city and city_near_y == query_city:
                res.append(None)
            elif city_near_x == query_city:
                res.append(city_near_y)
            elif city_near_y == query_city:
                res.append(city_near_x)
            else:
                dist1, dist2 = distance(c_map[query_city], c_map[city_near_x]), distance(c_map[query_city], c_map[city_near_y])
                if dist1<dist2:
                    res.append(city_near_x)
                else:
                    res.append(city_near_y)
    return res

Nearest Neighboring City โœ