๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.6K subscribers
5.6K photos
3 videos
95 files
10.5K 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
#include <vector>
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
int solution(vector<vector<int>>& chessboard) {
    int N = chessboard.size();
    vector<vector<pair<int, int>>> topTwoMax(N, vector<pair<int, int>>(2, {0, -1}));
    for (int i = 0; i < N; ++i) {
        int max1 = INT_MIN, max2 = INT_MIN;
        int idx1 = -1, idx2 = -1;

        for (int j = 0; j < chessboard[i].size(); ++j) {
            if (chessboard[i][j] >= max1) {
                max2 = max1;
                idx2 = idx1;
                max1 = chessboard[i][j];
                idx1 = j;
            } else if (chessboard[i][j] > max2) {
                max2 = chessboard[i][j];
                idx2 = j;
            }
        }

        topTwoMax[i][0] = {max1, idx1};
        topTwoMax[i][1] = {max2, idx2};
    }

    int maxSum = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            int sum = topTwoMax[i][0].first + topTwoMax[j][0].first;
            if (topTwoMax[i][0].second != topTwoMax[j][0].second) {
                maxSum = max(maxSum, sum);
            } else {
                sum = max(topTwoMax[i][0].first + topTwoMax[j][1].first,
                          topTwoMax[i][1].first + topTwoMax[j][0].first);
                maxSum = max(maxSum, sum);
            }
        }
    }

    return maxSum;
}
def solution(numbers, pivot):
    count_greater = 0
    count_less = 0

    for num in numbers:
        if num > pivot:
            count_greater += 1
        elif num < pivot:
            count_less += 1

    if count_greater > count_less:
        return "greater"
    elif count_greater < count_less:
        return "smaller"
    else:
        return "tie"

Autodesk โœ…
#include <iostream>
#include <vector>

using namespace std;

int solution(vector<int> &numbers) {
    for (size_t i = 1; i < numbers.size(); ++i) {
        if ((numbers[i] % 2) == (numbers[i - 1] % 2)) {
            return i;
        }
    }
    return -1;
}

Autodesk โœ…
๐Ÿ‘1
public boolean robotRectangle(String moves){
        if(moves.length()<1) return false;
        int upDown=0, rightLeft=0;
        char[] movesArr= moves.toCharArray();
        for(int i= 0; i< movesArr.length; i++){
            if(movesArr[i] == '^')  upDown++;
            else if(movesArr[i] == 'v')  upDown--;
            else if(movesArr[i] == '>')  rightLeft++;
            else if(movesArr[i] == '<')  rightLeft--;
        }
        return upDown== 0 && rightLeft== 0?true:false;   
    }
๐Ÿ‘2
#include <iostream>
#include <unordered_map>
#include <string>

using namespace std;

int solution(vector<int> &A) {
    int max_sum = -1; 

    unordered_map<int, int> same_digits; 

    for (int num : A) {
        int first_last = stoi(to_string(num).substr(0, 1) + to_string(num).substr(to_string(num).length() - 1)); 
        if (same_digits.find(first_last) != same_digits.end()) {
            max_sum = max(max_sum, same_digits[first_last] + num);
        } else {
            same_digits[first_last] = num;
        }
    }

    return max_sum;
}
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
using namespace std;
class SegmentTree {
private:
    vector<int> tree;
    int size;
public:
    SegmentTree(int n) {
        size = 1;
        while (size < n) {
            size *= 2;
        }
        tree.assign(2 * size, 0);
    }
    void update(int idx, int value) {
        idx += size;
        tree[idx] += value;
        while (idx > 1) {
            idx /= 2;
            tree[idx] = tree[2 * idx] + tree[2 * idx + 1];
        }
    }
    int query(int left, int right) {
        left += size;
        right += size + 1;
        int sum = 0;
        while (left < right) {
            if (left % 2 == 1) {
                sum += tree[left];
                left++;
            }
            if (right % 2 == 1) {
                right--;
                sum += tree[right];
            }
            left /= 2;
            right /= 2;
        }
        return sum;
    }
};
vector<int> solution(int numOfEmployees, int numOfQueries, vector<vector<int>>& queries) {
    SegmentTree seg_tree(numOfEmployees);
    vector<int> results;
    for (const auto& query : queries) {
        int q_type = query[0];
        if (q_type == 1) {
            int emp_id = query[1];
            int amount = query[2];
            seg_tree.update(emp_id, amount);
        } else if (q_type == 2) {
            int left = query[1];
            int right = query[2];
            results.push_back(seg_tree.query(left, right));
        }
    }
    return results;
}

Netapp โœ