IBM Oa Help | Oa Exam Helper
Відкрити в Telegram
We are here to clear All types of Exams Admin : @Codercpp001 (aka) KMK ✅ INTERVIEW HELP AVAILABLE 1-Coding Round 2-Aptitude and Reasoning Round 3-Communication round 4-Resume building 🎉Job updates will be posted here.
Показати більше1 156
Підписники
Немає даних24 години
Немає даних7 днів
+730 день
Архів дописів
long calculateTotalRegion(vector<int> heights) {
int n = heights.size();
vector<int> left(n, 1), right(n, 1);
stack<int> st;
for (int i = 0; i < n; ++i) {
while (!st.empty() && heights[st.top()] <= heights[i]) {
st.pop();
}
if (!st.empty()) {
left[i] = i - st.top();
} else {
left[i] = i + 1;
}
st.push(i);
}
while (!st.empty()) {
st.pop();
}
for (int i = n - 1; i >= 0; --i) {
while (!st.empty() && heights[st.top()] <= heights[i]) {
st.pop();
}
if (!st.empty()) {
right[i] = st.top() - i;
} else {
right[i] = n - i;
}
st.push(i);
}
long totalRegion = 0;
for (int i = 0; i < n; ++i) {
totalRegion += left[i] + right[i] - 1;
}
return totalRegion;
}
def calculateTotalRegion(heights):
n = len(heights)
left = [-1] * n
right = [n] * n
stack = []
for i in range(n):
while stack and heights[stack[-1]] < heights[i]:
right[stack.pop()] = i
stack.append(i)
stack.clear()
for i in range(n - 1, -1, -1):
while stack and heights[stack[-1]] < heights[i]:
left[stack.pop()] = i
stack.append(i)
total = 0
for i in range(n):
region_length = right[i] - left[i] - 1
total += region_length
return totallong long minimumWeeklyInput(vector costs, int weeks)
{
int n = costs.size();
vector> dp(n + 1, vector(weeks + 1, 1e18));
dp[0][0] = 0;
for (int w = 1; w <= weeks; ++w)
{
for (int i = 1; i <= n; ++i)
{
long long max_cost_in_week = 0;
for (int k = i; k > 0; --k)
{
max_cost_in_week = max(max_cost_in_week, (long long)costs[k - 1]);
if (dp[k - 1][w - 1] != 1e18)
{
dp[i][w] = min(dp[i][w], dp[k - 1][w - 1] + max_cost_in_week);
}
}
}
}
return dp[n][weeks];
}
Minimum weekly input
#include <iostream>
#include <queue>
#include <vector>
#include <tuple>
#include <climits>
using namespace std;
struct Point {
int x, y;
};
const vector<Point> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vector<vector<int>> bfs(const vector<vector<int>>& maze, Point start) {
int n = maze.size();
int m = maze[0].size();
vector<vector<int>> dist(n, vector<int>(m, INT_MAX));
queue<Point> q;
q.push(start);
dist[start.x][start.y] = 0;
while (!q.empty()) {
Point current = q.front();
q.pop();
for (auto dir : directions) {
int newX = current.x + dir.x;
int newY = current.y + dir.y;
if (newX >= 0 && newX < n && newY >= 0 && newY < m && maze[newX][newY] != 1) {
if (dist[newX][newY] > dist[current.x][current.y] + 1) {
dist[newX][newY] = dist[current.x][current.y] + 1;
q.push({newX, newY});
}
}
}
}
return dist;
}
int minMoves(vector<vector<int>>& maze, int x, int y) {
int n = maze.size();
int m = maze[0].size();
vector<Point> coins;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (maze[i][j] == 2) {
coins.push_back({i, j});
}
}
}
int coinCount = coins.size();
if (coinCount == 0) {
auto dist = bfs(maze, {0, 0});
return dist[x][y] == INT_MAX ? -1 : dist[x][y];
}
vector<Point> positions = {{0, 0}};
positions.insert(positions.end(), coins.begin(), coins.end());
positions.push_back({x, y});
int pSize = positions.size();
vector<vector<int>> distMatrix(pSize, vector<int>(pSize, INT_MAX));
for (int i = 0; i < pSize; ++i) {
auto dist = bfs(maze, positions[i]);
for (int j = 0; j < pSize; ++j) {
distMatrix[i][j] = dist[positions[j].x][positions[j].y];
}
}
for (int i = 0; i < pSize; ++i) {
for (int j = 0; j < pSize; ++j) {
if (distMatrix[i][j] == INT_MAX) {
return -1;
}
}
}
int coinMaskSize = 1 << coinCount;
vector<vector<int>> dp(coinMaskSize, vector<int>(coinCount, INT_MAX));
for (int i = 0; i < coinCount; ++i) {
dp[1 << i][i] = distMatrix[0][i + 1];
}
for (int mask = 0; mask < coinMaskSize; ++mask) {
for (int i = 0; i < coinCount; ++i) {
if (!(mask & (1 << i))) continue;
for (int j = 0; j < coinCount; ++j) {
if (mask & (1 << j)) continue;
int newMask = mask | (1 << j);
dp[newMask][j] = min(dp[newMask][j], dp[mask][i] + distMatrix[i + 1][j + 1]);
}
}
}
int minSteps = INT_MAX;
for (int i = 0; i < coinCount; ++i) {
minSteps = min(minSteps, dp[coinMaskSize - 1][i] + distMatrix[i + 1][pSize - 1]);
}
return minSteps;
}int solution(vector<int> arr, vector<vector<int>> mat) {
int totalUpdates = 0;
int n = arr.size();
for (const auto &query : mat) {
int X = query[0] - 1;
int Y = query[1];
int Z = query[2];
int bitMask = (1 << (Y - 1));
int endIndex = X;
while (endIndex < n && (arr[endIndex] & bitMask)) {
endIndex++;
}
int sizeToUpdate = endIndex - X;
if (sizeToUpdate > 0) {
for (int i = X; i < endIndex; ++i) {
arr[i] ^= Z;
}
totalUpdates += sizeToUpdate;
}
}
return totalUpdates;
}
Xor(Trilogy)✅typedef long long ll;
const int MOD = 1000000007;
ll power_mod(ll x, ll y, ll mod) {
ll res = 1;
x %= mod;
while(y >0){
if(y &1){
res = res * x % mod;
}
x = x * x % mod;
y >>=1;
}
return res;
}
vector<int> solve(vector<vector<int>> A){
const int MAX_N = 1000000;
vector<int> f(MAX_N +1, 0);
f[0]=0;
f[1]=0;
for(int n=2; n<=MAX_N; ++n){
if(n %2 ==1){
int k = n /2;
ll temp = (1LL + 2LL * f[k]) % MOD;
f[n] = temp;
}
else{
int k = n /2;
ll temp = (1LL + f[k -1] + f[k]) % MOD;
f[n] = temp;
}
}
vector<int> result;
result.reserve(A.size());
for(auto &query : A){
int L = query[0];
int R = query[1];
int n = R - L +1;
if(n ==1){
result.push_back(1);
continue;
}
int k = f[n];
ll P = (ll)(n) - (ll)(k);
ll Q = n;
ll inv_Q = power_mod(Q, MOD -2, MOD);
ll ans = (P * inv_Q) % MOD;
result.push_back((int)ans);
}
return result;
}
//probability
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef vector<vector<long long>> Matrix;
Matrix multiply(const Matrix &A, const Matrix &B) {
int n = A.size();
Matrix result(n, vector<long long>(n, 0));
for (int i = 0; i < n; ++i) {
for (int k = 0; k < n; ++k) {
if (A[i][k]) {
for (int j = 0; j < n; ++j) {
result[i][j] = (result[i][j] + A[i][k] * B[k][j]) % MOD;
}
}
}
}
return result;
}
Matrix matrix_power(Matrix base, long long exponent) {
int n = base.size();
Matrix result(n, vector<long long>(n, 0));
for (int i = 0; i < n; ++i)
result[i][i] = 1;
while (exponent > 0) {
if (exponent % 2 == 1)
result = multiply(result, base);
base = multiply(base, base);
exponent /= 1LL << 1;
}
return result;
}
int solve(long long A, int B, int C) {
if (A == 0)
return 0;
vector<long long> S0(B, 0);
S0[0] = C % MOD;
Matrix M(B, vector<long long>(B, 0));
for (int k = 0; k < B; ++k) {
if (k + 1 < B) {
M[k][k + 1] = 1;
}
M[k][0] = (C - 1) % MOD;
}
Matrix M_power = matrix_power(M, A - 1);
vector<long long> S(B, 0);
for (int i = 0; i < B; ++i) {
for (int j = 0; j < B; ++j) {
S[i] = (S[i] + S0[j] * M_power[j][i]) % MOD;
}
}
long long total = 0;
for (int i = 0; i < B; ++i) {
total = (total + S[i]) % MOD;
}
return (int)total;
}
Valid Array (Trilogy) ✅
vector>vp;
for(int j=0;jans;
sort(vp.begin(),vp.end());
reverse(vp.begin(),vp.end());
for(auto it:vp)
ans.push_back(it.second);
return ans;
#include <iostream>
#include <vector>
int countbalancingElements(vector<int>& arr) {
int n = arr.size();
int sumEven = 0, sumOdd = 0;
for (int i = 0; i < n; ++i) {
if (i % 2 == 0) {
sumEven += arr[i];
} else {
sumOdd += arr[i];
}
}
int count = 0;
int aa = 0, bb = 0;
for (int i = 0; i < n; ++i) {
if (i % 2 == 0) {
sumEven -= arr[i];
} else {
sumOdd -= arr[i];
}
if (aa + sumOdd == bb + sumEven) {
count++;
}
if (i % 2 == 0) {
aa += arr[i];
} else {
bb += arr[i];
}
}
return count;
}
Balancing Elements✅
Zscaler
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
vector<int> sortBitArrays(const vector<vector<int>>& v) {
vector<pair<long long, int>> vp;
for (int j = 0; j < v.size(); j++) {
long long x = 0;
for (auto it : v[j]) {
x |= (1LL << it);
}
vp.push_back({x, j});
}
sort(vp.begin(), vp.end(), [](const pair<long long, int>& a, const pair<long long, int>& b) {
return a.first > b.first;
});
unordered_set<int> uniqueIndices;
vector<int> ans;
for (const auto& it : vp) {
if (uniqueIndices.find(it.second) == uniqueIndices.end()) {
uniqueIndices.insert(it.second);
ans.push_back(it.second);
}
}
return ans;
}
Binary Storage ✅
Zscaler
#define pll pair<long long,long long>
#define vll vector<long long>
#define ll long long
#define vvll vector<vector<long long>>
#define vpll vector<pair<long long,long long>>
class Solution {
public:
bool isRobotBounded(string s) {
ll x=0,y=0;
ll d=0;
vvll dir={{0,1},{1,0},{0,-1},{-1,0}};
for(auto it:s)
{
if(it=='R') d=(d+1)%4;
else if(it=='L') d=(d+3)%4;
else x+=dir[d][0],y+=dir[d][1];
}
if(x==0 and y==0 or d>0) return 1;
return 0;
}
};
Encircular ✅
Zscaler
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
using namespace std;
string concatenate(const vector<string>& elements, const string& sep) {
string output;
for (size_t index = 0; index < elements.size(); ++index) {
output += elements[index];
if (index < elements.size() - 1) {
output += sep;
}
}
return output;
}
string handle_test_case(int numElements, int numQueries, vector<int>& positions, vector<int>& queryValues) {
unordered_map<int, int> frequencyMap;
for (int current = 1; current <= numElements; ++current) {
// Calculate coverage at position = positions[current]
int coverage = (current - 1) * (numElements - current + 1) + (numElements - current);
frequencyMap[coverage]++;
if (current < numElements) {
int gap = positions[current] - positions[current - 1] - 1;
if (gap > 0) {
int inBetween = current * (numElements - current);
frequencyMap[inBetween] += gap;
}
}
}
// Prepare answers for each query
vector<string> results;
for (int query : queryValues) {
results.push_back(to_string(frequencyMap[query]));
}
return concatenate(results, " ");
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int testCases;
cin >> testCases;
vector<string> allResults;
for (int i = 0; i < testCases; ++i) {
int numElements, numQueries;
cin >> numElements >> numQueries;
vector<int> positions(numElements);
for (int j = 0; j < numElements; ++j) {
cin >> positions[j];
}
vector<int> queryValues(numQueries);
for (int j = 0; j < numQueries; ++j) {
cin >> queryValues[j];
}
string result = handle_test_case(numElements, numQueries, positions, queryValues);
allResults.push_back(result);
}
cout << concatenate(allResults, "\n") << endl;
return 0;
}
Вже доступно! Дослідження Telegram за 2025 — головні інсайти року 
