๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
string solve(string s) {
    string pre, post;
    deque<char> sDeque(s.begin(), s.end());

    char minChar = *min_element(sDeque.begin(), sDeque.end());

    while (!sDeque.empty()) {

        pre.push_back(sDeque.front());
        sDeque.pop_front();

       
        if (!sDeque.empty() && pre.back() == minChar) {
            minChar = *min_element(sDeque.begin(), sDeque.end());
        }

        while (!pre.empty() && (sDeque.empty() || pre.back() <= minChar)) {
            post.push_back(pre.back());
            pre.pop_back();
        }
    }

    while (!pre.empty()) {
        post.push_back(pre.back());
        pre.pop_back();
    }

    return post;
}

DE Shaw โœ…
๐Ÿ‘3
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
class Dice {
public:
    int t, b, l, r, f, k;

    Dice() {
        t = 1; b = 6; l = 4; r = 3; f = 2; k = 5;
    }

    void rollRight() {
        int temp = t;
        t = l;
        l = b;
        b = r;
        r = temp;
    }

    void rollLeft() {
        int temp = t;
        t = r;
        r = b;
        b = l;
        l = temp;
    }

    void rollDown() {
        int temp = t;
        t = k;
        k = b;
        b = f;
        f = temp;
    }
};

int calculateCubeSum(int R, int C) {
    Dice dice;
    int s = 0;

    for (int i = 0; i < R; ++i) {
        if (i % 2 == 0) {
           
            for (int j = 0; j < C; ++j) {
                s += dice.t;
                if (j < C - 1) dice.rollRight();
            }
        } else {
           
            for (int j = C - 1; j >= 0; --j) {
                s += dice.t;
                if (j > 0) dice.rollLeft();
            }
        }
        if (i < R - 1) dice.rollDown();
    }

    return s;
}

Rolling a Dice โœ…
Goldman Sachs
โค1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void displayTheChannel(int N, vector<string>& channels, vector<int>& operations) {
    int i = 0;

    for (auto op : operations) {
        if (op == 1) {
            if (i < N - 1) {
                swap(channels[i], channels[i + 1]);
                i++;
            }
        } else if (op == 2) {
            if (i > 0) {
                swap(channels[i], channels[i - 1]);
                i--;
            }
        } else if (op == 3) {
            if (i < N - 1) {
                swap(channels[i], channels[i + 1]);
                i++;
            }
        }
   
    }

    for (const auto& channel : channels) {
        cout << channel << endl;
    }
}

int main() {
    int N;
    cin >> N; // Number of channels

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

    int M;
    cin >> M;

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

    displayTheChannel(N, channels, operations);

    return 0;
}

// CHANNEL SEQUENCE โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <sstream>
#include <unordered_map>

using namespace std;

void generateResult(int N, int M, vector<string>& employeeSalaryAndSuperior, vector<string>& operations) {
    vector<int> salaries(N, 0);
    unordered_map<int, vector<int>> supervisors;

    for (int i = 0; i < N; ++i) {
        stringstream ss(employeeSalaryAndSuperior[i]);
        int salary, supervisor;
        ss >> salary >> supervisor;
        salaries[i] = salary;
        if (supervisor != -1) {
            supervisors[supervisor - 1].push_back(i);
        }
    }

    for (int i = 0; i < M; ++i) {
        stringstream ss(operations[i]);
        char type;
        ss >> type;
        if (type == 'p') {
            int A, X;
            ss >> A >> X;
            A -= 1;
            for (int subordinate : supervisors[A]) {
                salaries[subordinate] += X;
            }
        } else if (type == 'u') {
            int B;
            ss >> B;
            B -= 1;
            cout << salaries[B] << endl;
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    cin.ignore();

    vector<string> employeeSalaryAndSuperior(N);
    for (int i = 0; i < N; ++i) {
        getline(cin, employeeSalaryAndSuperior[i]);
    }

    vector<string> operations(M);
    for (int i = 0; i < M; ++i) {
        getline(cin, operations[i]);
    }

    generateResult(N, M, employeeSalaryAndSuperior, operations);
    return 0;
}

Salary fluctuations โœ…
๐Ÿ‘1
def solution(a):
    if not a:
        return []
   
    result = []
    for i in range(len(a)):
        first_char = a[i][0]
        if i == len(a) - 1:
            last_char = a[0][-1]
        else:
            last_char = a[i + 1][-1]
        result.append(first_char + last_char)
   
    return result

Databrick โœ…
def bird_nest(forest, bird):
    nest = []
    total_length = 0
    direction = 1
    current_position = bird
    visited = set()

    while total_length < 100:
        while forest[current_position] == 0 or current_position in visited:
            current_position += direction

        nest.append(current_position)
        total_length += forest[current_position]
        visited.add(current_position)

        current_position = bird
        direction *= -1

    return nest

Databrick โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
List<Integer> results = new ArrayList<>();
    int counter = 1;
    Map<Integer, Integer> allocationMap = new HashMap<>();

    for (int[] query : queries) {
        if (query[0] == 0) {
            int length = query[1];
            int result = -1;
            for (int i = 0; i <= memory.length - length; i++) {
                boolean canAllocate = true;
                for (int j = 0; j < length; j++) {
                    if (memory[i + j] != 0) {
                        canAllocate = false;
                        break;
                    }
                }
                if (canAllocate) {
                    for (int j = 0; j < length; j++) {
                        memory[i + j] = counter;
                    }
                    allocationMap.put(counter, length);
                    result = counter++;
                    break;
                }
            }
            results.add(result);
        } else if (query[0] == 1) {
            int id = query[1];
            if (!allocationMap.containsKey(id)) {
                results.add(-1);
                continue;
            }
            int length = allocationMap.get(id);
            boolean erased = false;
            for (int i = 0; i < memory.length; i++) {
                if (memory[i] == id) {
                    for (int j = 0; j < length; j++) {
                        memory[i + j] = 0;
                    }
                    allocationMap.remove(id);
                    results.add(length);
                    erased = true;
                    break;
                }
            }
            if (!erased) {
                results.add(-1);
            }
        }
    }

    int[] resultArray = new int[results.size()];
    for (int i = 0; i < results.size(); i++) {
        resultArray[i] = results.get(i);
    }
    return resultArray;
}