#include <iostream>
#include <vector>
using namespace std;
long makePowerNondecreasing(vector<int>& power) {
int n = power.size();
long adjustments = 0;
for (int i = 1; i < n; ++i) {
if (power[i] < power[i - 1]) {
adjustments += power[i - 1] - power[i];
}
}
return adjustments;
}
Amazon
Telegram:- @allcoding1
#include <vector>
using namespace std;
long makePowerNondecreasing(vector<int>& power) {
int n = power.size();
long adjustments = 0;
for (int i = 1; i < n; ++i) {
if (power[i] < power[i - 1]) {
adjustments += power[i - 1] - power[i];
}
}
return adjustments;
}
Amazon
Telegram:- @allcoding1
👍1
allcoding1
Photo
#include <iostream>
#include <vector>
using namespace std;
class SinglyLinkedListNode {
public:
string data;
SinglyLinkedListNode* next;
SinglyLinkedListNode(string value) {
data = value;
next = nullptr;
}
};
SinglyLinkedListNode* getShoppingCart(SinglyLinkedListNode* head, vector<vector<string>> queries) {
for (auto& query : queries) {
string action = query[0];
string item_name = query[1];
if (action == "PUSH_HEAD") {
SinglyLinkedListNode* new_node = new SinglyLinkedListNode(item_name);
new_node->next = head;
head = new_node;
} else if (action == "PUSH_TAIL") {
SinglyLinkedListNode* new_node = new SinglyLinkedListNode(item_name);
if (head == nullptr) {
head = new_node;
} else {
SinglyLinkedListNode* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = new_node;
}
} else if (action == "POP_HEAD") {
if (head != nullptr) {
SinglyLinkedListNode* temp = head;
head = head->next;
delete temp;
}
}
}
return head;
}
Amazon
#include <vector>
using namespace std;
class SinglyLinkedListNode {
public:
string data;
SinglyLinkedListNode* next;
SinglyLinkedListNode(string value) {
data = value;
next = nullptr;
}
};
SinglyLinkedListNode* getShoppingCart(SinglyLinkedListNode* head, vector<vector<string>> queries) {
for (auto& query : queries) {
string action = query[0];
string item_name = query[1];
if (action == "PUSH_HEAD") {
SinglyLinkedListNode* new_node = new SinglyLinkedListNode(item_name);
new_node->next = head;
head = new_node;
} else if (action == "PUSH_TAIL") {
SinglyLinkedListNode* new_node = new SinglyLinkedListNode(item_name);
if (head == nullptr) {
head = new_node;
} else {
SinglyLinkedListNode* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = new_node;
}
} else if (action == "POP_HEAD") {
if (head != nullptr) {
SinglyLinkedListNode* temp = head;
head = head->next;
delete temp;
}
}
}
return head;
}
Amazon
👍6🔥1
🎯OLA is hiring for Software Developer Intern
Stipend: ₹ 30k - ₹ 50k
Apply Now:- https://docs.google.com/forms/d/e/1FAIpQLSfuOSPDwkjNlXkpo4zA9_GACQxwr3lMae2YFFu6L0-6irBF4Q/viewform
Stipend: ₹ 30k - ₹ 50k
Apply Now:- https://docs.google.com/forms/d/e/1FAIpQLSfuOSPDwkjNlXkpo4zA9_GACQxwr3lMae2YFFu6L0-6irBF4Q/viewform
👍2