allcoding1
27.7K subscribers
2.2K photos
2 videos
77 files
852 links
Download Telegram
Integer array A of size n.... Code

HackWithInfy

@allcoding1
#include <iostream>
#include <string>
#include <algorithm>

int findLargestX(std::string&amp; str) {
int max_x = 0;
int sum = 0;

for (char c : str) {
if (isdigit(c)) {
sum += c - '0';
} else if (c == '-') {
max_x = std::max(max_x, sum);
sum = 0;
}
}

return max_x;
}

int main() {
std::string input = "63-1+2-1+3+4-9-1+2-3-3+4+9";
int largest_x = findLargestX(input);

std::cout &lt;&lt; "Largest value of x: " &lt;&lt; largest_x &lt;&lt; std::endl;

return 0;
}

Maximum_Subarray

C++

HackWithInfy

@allcoding1
πŸ‘2
#include <iostream>
#include <vector>
#include <unordered_map>

const int MOD = 1000000007;

int countUniqueArrangements(std::vector<std::pair<int, int="">&gt;&amp; dominoes) {
std::unordered_map<int, int=""> dp;
dp[0] = 1; // Base case
int n = dominoes.size();

for(int i = 1; i &lt;= n; ++i) {
std::unordered_map<int, int=""> next_dp;

for(auto&amp; domino : dominoes) {
int key = dp.count(domino.first) ? domino.first : domino.second;
next_dp[key] = (next_dp[key] + dp[key ^ domino.first ^ domino.second]) % MOD;
}

dp = std::move(next_dp);
}

int total_arrangements = 0;
for(auto&amp; p : dp) {
total_arrangements = (total_arrangements + p.second) % MOD;
}

return total_arrangements;
}

int main() {
int N;
std::cin &gt;&gt; N;

std::vector<std::pair<int, int="">&gt; dominoes(N);
for(int i = 0; i &lt; N; ++i) {
std::cin &gt;&gt; dominoes[i].first &gt;&gt; dominoes[i].second;
}

int total_arrangements = countUniqueArrangements(dominoes);

std::cout &lt;&lt; total_arrangements &lt;&lt; std::endl;

return 0;
}

C++
You are given a set of dominoes each with two sides. Each side is marked with dots ranging from 1 to 6.

HackWithInfy

@allcoding1
πŸ‘1
#include <iostream>
#include <vector>
#include <unordered_map>

const int MOD = 1000000007;
int n, m, startRow, startColumn, moves, q;
std::vector<std::vector<int>&gt; obstacles;

bool isObstacle(int x, int y) {
for (auto&amp; obstacle : obstacles) {
if (obstacle[0] == x &amp;&amp; obstacle[1] == y) {
return true;
}
}
return false;
}

int countPaths(int x, int y, int movesLeft, std::unordered_map<std::string, int="">&amp; dp) {
if (x &lt; 0 y &lt; 0 x &gt;= n || y &gt;= m) {
return 1;
}
if (movesLeft == 0 || isObstacle(x, y)) {
return 0;
}

std::string key = std::to_string(x) + ":" + std::to_string(y) + ":" + std::to_string(movesLeft);
if (dp.find(key) != dp.end()) {
return dp[key];
}

int paths = countPaths(x + 1, y, movesLeft - 1, dp) % MOD;
paths = (paths + countPaths(x - 1, y, movesLeft - 1, dp)) % MOD;
paths = (paths + countPaths(x, y + 1, movesLeft - 1, dp)) % MOD;
paths = (paths + countPaths(x, y - 1, movesLeft - 1, dp)) % MOD;

dp[key] = paths;
return paths;
}

int main() {
std::cin &gt;&gt; n &gt;&gt; m &gt;&gt; startRow &gt;&gt; startColumn &gt;&gt; moves &gt;&gt; q;

obstacles.resize(q, std::vector<int>(2));
for (int i = 0; i &lt; q; ++i) {
std::cin &gt;&gt; obstacles[i][0] &gt;&gt; obstacles[i][1];
}

std::unordered_map<std::string, int=""> dp;
int totalPaths = countPaths(startRow, startColumn, moves, dp);

std::cout &lt;&lt; totalPaths &lt;&lt; std::endl;

return 0;
}

C++

In a town called Gridland, there lived a man named Alex who had a special skill. He could move around a grid like a big square map. The grid had obstacles, things he couldn't go through.

The grid is described by its size n x m, and Alex starts at a specΓ­fic position [startRow, startColumn). There are also obstacles in fixed positions.

HackWithInfy

@allcoding1
πŸ‘3❀1
https://www.allcoding1.com/2023/12/allcoding1-answers.html?m=1


πŸ†“ Copy ur question and past you get Answer
πŸ‘1
#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