๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.69K 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 <bits/stdc++.h>
using namespace std;

class SinglyLinkedListNode {
public:
    int data;
    SinglyLinkedListNode* next;

    SinglyLinkedListNode(int node_data) {
        this->data = node_data;
        this->next = nullptr;
    }
};

SinglyLinkedListNode* findLongestList(SinglyLinkedListNode* head) {
    if (!head) return nullptr;

    SinglyLinkedListNode* curr = head;
    SinglyLinkedListNode* start = head;
    SinglyLinkedListNode* bestStart = head;

    int length = 1;
    int bestLength = 1;

    while (curr->next) {
        if (curr->data >= curr->next->data) {
            length++;
        } else {
            if (length > bestLength) {
                bestLength = length;
                bestStart = start;
            }
            length = 1;
            start = curr->next;
        }
        curr = curr->next;
    }

    // Check at the end in case the best sub-list is at the very end.
    if (length > bestLength) {
        bestLength = length;
        bestStart = start;
    }

    // Truncate the list after the longest non-increasing sub-list
    SinglyLinkedListNode* temp = bestStart;
    for (int i = 1; i < bestLength && temp; i++) {
        temp = temp->next;
    }
    if (temp) {
        temp->next = nullptr;
    }

    return bestStart;
}

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

vector<int> getMeanRankCount(vector<int>& rank) {
    int n = rank.size();
    vector<long long> prefixSum(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        prefixSum[i + 1] = prefixSum[i] + rank[i];
    }

    vector<int> res(n, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            long long sum = prefixSum[j + 1] - prefixSum[i];
            long long len = j - i + 1;
           
            if (sum % len == 0) {
                long long mean = sum / len;
                if (mean <= n) {
                    res[mean - 1]++;
                }
            }
        }
    }
    return res;
}

int main() {
    vector<int> ranks = {4,7,3,6,5,2,1};
    vector<int> result = getMeanRankCount(ranks);
   
    for (int val : result) {
        cout << val << " ";
    }
    return 0;
}

Amazon C++โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include<bits/stdc++.h>
using namespace std;

vector<int> twoDimensions(vector<string> coordinates, int n) {
    vector<int> maxAndCount(2);
    vector<vector<int>> grid(n, vector<int>(n, 0));
    int arrLength = coordinates.size();
    int max_val = INT_MIN;
    int count = 1;

    for (int i = 0; i < arrLength; i++) {
        stringstream ss(coordinates[i]);
        int row, column;
        ss >> row >> column;

        for (int j = 0; j < row; j++) {
            for (int k = 0; k < column; k++) {
                grid[j][k] += 1;

                if (grid[j][k] > max_val) {
                    max_val = grid[j][k];
                    count = 1;
                } else if (grid[j][k] == max_val) {
                    count++;
                }
            }
        }
    }

    maxAndCount[0] = max_val;
    maxAndCount[1] = count;

    return maxAndCount;
}

int main() {
    vector<string> coors = { "2 3", "3 7", "4 1"};
    vector<int> result = twoDimensions(coors, 7);  // Change 3 to 7 for the grid size
    cout <<result[1] << endl;
    return 0;
}

Oracle โœ…
Growth in 2 Dimension
from queue import Queue

def solution(N, A, B, M):
    degree = [0] * N
    for i in range(M):
        degree[A[i]] += 1
        degree[B[i]] += 1

    q = Queue()
    for i in range(N):
        if degree[i] <= 1:
            q.put(i)

    seconds = 0
    while not q.empty():
        q_size = q.qsize()
        for i in range(q_size):
            vertex = q.get()

            for j in range(M):
                if A[j] == vertex or B[j] == vertex:
                    other_vertex = B[j] if A[j] == vertex else A[j]
                    degree[other_vertex] -= 1
                    if degree[other_vertex] == 1:
                        q.put(other_vertex)
        seconds += 1

    return seconds

Python 3โœ