vector<long long> solution(int t, vector<vector<long long>> carPrices) {
vector<long long> ans;
for (int i = 0; i < t; i++) {
vector<long long> arr = carPrices[i];
long long result = 0;
long long maxDiff = INT_MIN;
int N = arr.size();
for (int j = 0; j < N; j++) {
long long current = arr[j];
maxDiff = max(maxDiff, current);
result = max(result, maxDiff - current);
}
long long res = 0;
while ((1LL << res) - 1 < result) {
++res;
}
cout << res << endl;
ans.push_back(res);
}
return ans;
}
UBER CAR workingโค5๐3
bool fun(vector<int>& arr) {
int sum = 0;
for (int num : arr) {
sum += num;
}
int average = round(sum / arr.size());
for (int num : arr) {
if (num == average) {
return true;
}
}
return false;
}
allenโค5๐3
def check_average_in_array(arr):python code for 1st
average = round(sum(arr) / len(arr))
return average in arr
๐4
int calculateShortestPath(int numStops, vector<int> credits, int numRoads, vector<vector<int>> roads, int source, int dest)3rd working all verified
{
vector<vector<pair<int, int>>> adjacencyList(numStops);
for (int i = 0; i < numRoads; i++) {
int u = roads[i][0];
int v = roads[i][1];
int weight = roads[i][2];
adjacencyList[u].push_back({v, weight});
adjacencyList[v].push_back({u, weight});
}
vector<int> distances(1e6 + 5, 0x3f3f3f3f);
priority_queue<pair<int, int>> pq;
int initialNode = credits[source] * numStops + source;
pq.push({0, initialNode});
distances[initialNode] = 0;
while (!pq.empty()) {
auto currentPair = pq.top();
int currentDistance = currentPair.first;
int currentNode = currentPair.second;
int currentCredit = currentNode / numStops;
int currentVertex = currentNode % numStops;
pq.pop();
if (currentVertex == dest) {
return -currentDistance;
}
for (auto neighbor : adjacencyList[currentVertex]) {
int neighborVertex = neighbor.first;
int weight = neighbor.second;
if (weight > currentCredit) continue;
int newCredit = currentCredit - weight + credits[neighborVertex];
int newScore = newCredit * numStops + neighborVertex;
if (newCredit > 1e4) continue;
if (distances[newScore] > distances[currentNode] + weight) {
distances[newScore] = distances[currentNode] + weight;
pq.push({-(distances[currentNode] + weight), newScore});
}
}
}
return -1;
}
๐ฅ5๐2โค1
https://t.me/oahelp -> share with your friends for free OA sol and materials for free...๐
โค4๐1
https://t.me/oadiscussion -> join discussion grp for oa help and all send your OA ques here so that i can solve and other people too...
Telegram
Free code help
Gupshup,OAs discussion, career advice Join our main group - https://t.me/oahelp
โค3
Channel name was changed to ยซMedia.net Oracle| Deshaw| Uber|Google| Microsoft| Sprinkler| Codeforces| Codechef| leetcode| Gfg| OAs solutionยป
Channel name was changed to ยซMedia.net |Oracle| Deshaw| Uber|Google| Microsoft| Sprinkler| Codeforces| Codechef| leetcode| Gfg| OAs solutionยป
Thoda support Karo guys 1000 subscriber's karwa do....will try to bring more oa and solutions like this for free...
โค14โก3๐1
class DisjointSetUnion {
public:
void initialize(int numberOfElements) {
parent.resize(numberOfElements);
for (int i = 0; i < numberOfElements; ++i)
parent[i] = i;
}
int findRoot(int element) {
if (parent[element] != element)
parent[element] = findRoot(parent[element]);
return parent[element];
}
void unite(int element1, int element2) {
int root1 = findRoot(element1);
int root2 = findRoot(element2);
if (root1 != root2)
parent[root1] = root2;
}
private:
vector<int> parent;
};
string solve(vector<string>& words) {
int wordCount = words.size();
DisjointSetUnion dsu;
dsu.initialize(26);
vector<int> inDegrees(26, 0);
vector<int> outDegrees(26, 0);
vector<bool> isConnected(26, false);
string result;
for (int k = 0; k < wordCount; ++k) {
int start = words[k][0] - 'a';
int end = words[k].back() - 'a';
outDegrees[start]++;
inDegrees[end]++;
dsu.unite(start, end);
isConnected[start] = isConnected[end] = true;
int root = dsu.findRoot(start);
unordered_set<int> roots;
for (int i = 0; i < 26; ++i) {
if (isConnected[i] && (inDegrees[i] > 0 || outDegrees[i] > 0))
roots.insert(dsu.findRoot(i));
}
if (roots.size() > 1) {
result.push_back('0');
continue;
}
vector<int> differences;
for (int i = 0; i < 26; ++i) {
if (isConnected[i] && (inDegrees[i] > 0 || outDegrees[i] > 0))
differences.push_back(outDegrees[i] - inDegrees[i]);
}
if (!differences.empty()) {
int maxDifference = *max_element(differences.begin(), differences.end());
int minDifference = *min_element(differences.begin(), differences.end());
if (!((maxDifference == 0 && minDifference == 0) || (maxDifference == 1 && minDifference == -1 && count(differences.begin(), differences.end(), 1) == 1 && count(differences.begin(), differences.end(), -1) == 1))) {
result.push_back('0');
continue;
}
}
result.push_back('1');
}
return result;
}
MS 2ndโค12๐7
int countGoodSubsets(std::vector<int>& numbers) {
int maskArray[31] = {-1, 0, 1, 2, -1, 4, 3, 8, -1, -1, 5, 16, -1, 32, 9, 6, -1, 64, -1, 128, -1, 10, 17, 256, -1, -1, 33, -1, -1, 512, 7 };
int dp[1025] = {1}, count[31] = {};
for (int i = 0; i < numbers.size(); ++i)
++count[numbers[i]];
for (int i = 2; i <= 30; ++i) {
if (maskArray[i] > -1) {
for (int mi = maskArray[i], mj = 0; mj < 1024; ++mj) {
if ((mi & mj) == 0) {
dp[mi | mj] = (dp[mi | mj] + (long long)count[i] * dp[mj]) % 1000000007;
}
}
}
}
int result = std::accumulate(begin(dp) + 1, end(dp), 0, [](int sum, int num) { return (sum + num) % 1000000007; });
while (--count[1] >= 0)
result = (result << 1) % 1000000007;
return result;
} OMEGA ACโค4๐1
Send your coding ques and OA (any) ques here in this grp....other people and I will try to help you in yours OA's for free...just send your ques in this grp
https://t.me/oadiscussion
https://t.me/oadiscussion
Telegram
Free code help
Gupshup,OAs discussion, career advice Join our main group - https://t.me/oahelp
โค10
#include <bits/stdc++.h>seat booking sprinkler
using namespace std;
int main() {
int num_items, num_groups;
cin >> num_items >> num_groups;
vector<int> items(num_items);
for (int i = 0; i < num_items; ++i) {
cin >> items[i];
}
vector<int> group_sizes(num_groups);
for (int i = 0; i < num_groups; ++i) {
cin >> group_sizes[i];
}
sort(items.rbegin(), items.rend());
int max_profit = 0;
int idx = 0;
for (int i = 0; i < num_groups; ++i) {
int group_size = group_sizes[i];
while (idx < num_items && group_size > 0) {
max_profit += items[idx];
idx++;
group_size--;
}
}
cout << max_profit << endl;
return 0;
}
โค4๐3