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

int main ()
{
  int n; cin >> n;
  vector<int> b(n), a;
  for (auto & x : b) cin >> x;

  int X; cin >> X;
  for (int i = 0; i < X; i++) {
    vector<int> newb(n);
    for (int i = 0; i < n; i++) {
      newb[i] = abs(b[i] - b[(i+1)%n]);
    }
    a = b;
    b = newb;   
  }
  cout << "A: ";
  for (auto x : a) cout << x << " ";
  cout << endl;
  cout << "B: ";
  for (auto x : b) cout << x << " ";
  cout << endl;
}


Micron โœ…
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;
    }
    if (length > bestLength) {
        bestLength = length;
        bestStart = start;
    }
    SinglyLinkedListNode* temp = bestStart;
    for (int i = 1; i < bestLength && temp; i++) {
        temp = temp->next;
    }
    if (temp) {
        temp->next = nullptr;
    }

    return bestStart;
}

Amazon OA| AWS Databased
C++โœ…
long findTotalExecutionTime(vector<int>& execution) {
    int n = execution.size();
    vector<int> original = execution;
    long totalTime = 0;
    unordered_map<int, list<int>> origIndicesMap;

    for (int i = 0; i < n; i++) {
        origIndicesMap[original[i]].push_back(i);
    }

    for (int i = 0; i < n; i++) {
        totalTime += execution[i];

        if (origIndicesMap[original[i]].size() > 1) {
            int reducedValue = ceil((double)execution[i] / 2);
            for (int idx : origIndicesMap[original[i]]) {
                if (idx != i) {
                    execution[idx] = reducedValue;
                }
            }
        }
    }

    return totalTime;
}

Amazon
C++ โœ…
class Solution {
public:
    bool isAnagram(string s, string t) {
        sort(s.begin(), s.end());
        sort(t.begin(), t.end());
        return s == t;
    }
};

int number = 15;
    int n = (int)(log2(number));
  
    // binary output
    // using the inbuilt function
    cout << "the binary number is : "
         << bitset<64>(number).to_string().substr(64 - n
                                                  - 1);
}

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

int findMin(vector<int>& nums) {
    int low = 0, high = nums.size() - 1, ans = INT_MAX;
    while (low <= high) {
        int mid = (low + high) / 2;
        if (nums[low] <= nums[mid]) {
            ans = std::min(ans, nums[low]);
            low = mid + 1;
        } else {
            ans = std::min(ans, nums[mid]);
            high = mid - 1;
        }
    }
    return ans;
}

int main() {
    int n;
   
    cin >> n;
   
    vector<int> nums(n);
   
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }
   
    int result = findMin(nums);
    cout<< result << endl;
   
}

Helpshift โœ…
Ashley
#include<iostream>
using namespace std;

int main() {
    int sample;
    cin >> sample;

    for(int i = 0; i < sample; i++) {
        int item;
        cin >> item;

        int count = 0;
        while(item != 1) {
            if(item % 2 == 0) {
                item /= 2;
            } else {
                item -= 1;
            }
            count++;
        }

        cout <<count << endl;
    }

    return 0;
}

Multiplication tricks โœ…
Helpshift
#include <bits/stdc++.h>

using namespace std;

int count(vector<int>&coins, int n, int sum)
{

int table[sum + 1];


memset(table, 0, sizeof(table));


table[0] = 1;

for (int i = 0; i < n; i++)
  for (int j = coins[i]; j <= sum; j++)
   table[j] += table[j - coins[i]];
return table[sum];
}

int main()
{
int n,t;
cin>>n>>t;
vector<int>L(t);
for(int i=0;i<t;i++)
{
   cin>>L[i];
}

cout << count(L, t,n);

}

Helpshift โœ…
Goblin
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
    vector<vector<int>> ans;
    multiset<int> pq{0};
   
    vector<pair<int, int>> points;
   
    for(auto b: buildings){
        points.push_back({b[0], -b[2]});
        points.push_back({b[1], b[2]});
    }
   
    sort(points.begin(), points.end());
   
    int ongoingHeight = 0;
   
  
    for(int i = 0; i < points.size(); i++){
        int currentPoint = points[i].first;
        int heightAtCurrentPoint = points[i].second;
       
        if(heightAtCurrentPoint < 0){
            pq.insert(-heightAtCurrentPoint);
        } else {
            pq.erase(pq.find(heightAtCurrentPoint));
        }
       
      
        auto pqTop = *pq.rbegin();
        if(ongoingHeight != pqTop){
            ongoingHeight = pqTop;
            ans.push_back({currentPoint, ongoingHeight});
        }
    }
   
    return ans;
}

int main() {
    int n;
   
    cin >> n;

    vector<vector<int>> buildings(n, vector<int>(3));

   
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> buildings[i][j];
        }
    }

    vector<vector<int>> result = getSkyline(buildings);
  
    for (auto &p : result) {
        cout << p[0]<<p[1]<< endl;
    }

   
}

Skyline โœ…
#include <bits/stdc++.h>

using namespace std;

void minimumBribes(vector<int> A)
{
    int n = A.size();
    int cnt = 0;
    for(int i = n - 1; i >= 0; i--)
    {
        if(A[i] != (i + 1))
        {
            if(((i - 1) >= 0) && A[i - 1] == (i + 1))
            {
                cnt++;
                swap(A[i], A[i-1]);
            }
            else if(((i - 2) >= 0) && A[i - 2] == (i + 1))
            {
                cnt += 2;
                A[i - 2] = A[i - 1];
                A[i - 1] = A[i];
                A[i] = i + 1;
            }
            else
            {
                cout << "Too chaotic" << endl;
                return;
            }
        }     
    }
    cout << cnt << endl;
    return;
}

int main() {
    int t;
   
    cin >> t;

    for (int i = 0; i < t; i++) {
        int n;
       
        cin >> n;

        vector<int> A(n);
       
        for (int j = 0; j < n; j++) {
            cin >> A[j];
        }

        minimumBribes(A);
    }

    return 0;
}
Min bribes โœ