Messages in this channel will be automatically deleted after 1 day
Messages in this channel will be automatically deleted after 1 month
Messages in this channel will no longer be automatically deleted
👍3⚡1
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