allcoding1
27.7K subscribers
2.2K photos
2 videos
77 files
852 links
Download Telegram
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 1e9 + 7;

int main() {
    int N, Q;
    cin >> N;

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

    cin >> Q;

    long long sum = 0;
    for (int q = 0; q < Q; ++q) {

        int type, L, R, X, i , zero1 , zero2;
        cin >> type;

        if (type == 1) {
            cin >> L >> R >> X;
            for (int j = L-1; j < R; ++j) {
                A[j] = min(A[j], X);
            }
        } else if (type == 2) {
           
            cin >> i >> zero1 >>zero2;

            sum = (sum + A[i - 1]) % MOD;
        }

    }

    cout << sum << endl;

    return 0;
}

Replace by Minimum Code
C++
HackWithInfy

Telegram:- @allcoding1
MOD = 10**9 + 7

def solve(arrival_departure):
    arrival_departure.sort(key=lambda x: x[1])
    prev_departure = -1
    total_stations = 0

    for arrival, departure in arrival_departure:
        if arrival > prev_departure:
            total_stations += 1
            prev_departure = departure

    return total_stations % MOD

def main():
    N = int(input())
    arrival_departure = []
    for _ in range(N):
        arrival, departure = map(int, input().split())
        arrival_departure.append((arrival, departure))
   
    result = solve(arrival_departure)
    print(result)

if name == "main":
    main()

Trains Code
Python

HackWithInfy

Telegram:- @allcoding1
👍2
Forwarded from allcoding1
📌IT learning courses
📌All programing courses
📌Abdul bari courses
📌Ashok IT

100 rupees

Contact:- @meterials_available
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int getSmallestArea(vector<vector<int>>& grid) {
    int rows = grid.size();
    if (rows == 0) return 0;
    int cols = grid[0].size();
    if (cols == 0) return 0;

    set<int> rowsSet, colsSet;

    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            if (grid[i][j] == 1) {
                rowsSet.insert(i);
                colsSet.insert(j);
            }
        }
    }

    int width = colsSet.empty() ? 0 : *colsSet.rbegin() - *colsSet.begin() + 1;
    int height = rowsSet.empty() ? 0 : *rowsSet.rbegin() - *rowsSet.begin() + 1;

    return width * height;


shipping space
Salesforce

Telegram:- @allcoding1
👏1
import heapq
def reduce_sum(lst):
    heapq.heapify(lst)
    s = 0
    while len(lst) > 1:
        first = heapq.heappop(lst)
        second = heapq.heappop(lst)
        s += first + second
        heapq.heappush(lst, first + second)
    return s

Reduce the Array
Salesforce

Telegram:- @allcoding1
#include <iostream>
#include <vector>
#include <algorithm>

int getPotentialOfWinner(std::vector<int>& potential, long long k) {
    int n = potential.size();

    int x = potential[0];
    int m = 0;
    for (int i = 1; i < n; i++) {
        if (m != k) {
            if (x > potential[i]) {
                m++;
            } else {
                x = potential[i];
                m = 1;
            }
        }
    }

    return x;
}

int main() {
    std::vector<int> potentials = {3, 2, 1, 4};
    long long k = 2;
    std::cout << getPotentialOfWinner(potentials, k) << std::endl;
    return 0;
}

Potential winner code

Telegram:- @allcoding1
👍2
int minimumKeypresses(string s) {
        unordered_map<char, int> counts;
        for (char ch : s) {
            counts[ch]++;
        }

        vector<int> frequencies;
        for (const auto& kvp : counts) {
            frequencies.push_back(kvp.second);
        }

        sort(frequencies.begin(), frequencies.end(), greater<int>());

        vector<int> remain {9, 9, 9};
        int i = 0, total = 0;
        for (int count : frequencies) {
            total += count * (i + 1);
            remain[i]--;
            if (remain[i] == 0) {
                i++;
            }
        }
       
        return total;
    }

Amazon

Telegram:- @allcoding1
1👍1
def processExecution(power, minPower, maxPower):
    result = []
    for min_p, max_p in zip(minPower, maxPower):
        count = sum(1 for p in power if min_p <= p <= max_p)
        power_sum = sum(p for p in power if min_p <= p <= max_p)
        result.append((count, power_sum))
    return result

Amazon

Telegram:- @allcoding1
3👍1
TCS FREE NQT - Biggest Mass Hiring

Graduation Year: 2024

Eligibility: BTech / BE / MTech / ME / MCA / MSc / MS

Experience: Freshers

Salary:
Ninja - 3.36 LPA
Digital - 7 LPA
Prime - 9 LPA for UG and 11.5 LPA for PG

Apply now:-  www.allcoding1.com


Registration End Date: 10 April 2024
Test Date: 26th April Onwards

Telegram:- @allcoding1
👍4