class SuperMarket {
private Map<Integer, Customer> customers = new HashMap<>();
private Map<Integer, Queue<Customer>> lines = new HashMap<>();
public void OnCustomerEnter(int customerId, int lineNumber, int numItems) {
Customer customer = new Customer(customerId, lineNumber, numItems);
customers.put(customerId, customer);
if (!lines.containsKey(lineNumber)) {
lines.put(lineNumber, new LinkedList<>());
}
lines.get(lineNumber).add(customer);
}
public void OnBasketChange(int customerId, int newNumItems) {
Customer customer = customers.get(customerId);
int oldNumItems = customer.getNumItems();
customer.setNumItems(newNumItems);
if (oldNumItems > newNumItems) {
return;
}
Queue<Customer> line = lines.get(customer.getLineNumber());
line.remove(customer);
line.add(customer);
}
public void OnLineService(int lineNumber, int numProcessedItems) {
Queue<Customer> line = lines.get(lineNumber);
if (line.isEmpty()) {
return;
}
Customer customer = line.peek();
int numItems = customer.getNumItems();
if (numItems <= numProcessedItems) {
line.remove();
customers.remove(customer.getCustomerId());
System.out.println(customer.getCustomerId());
} else {
customer.setNumItems(numItems - numProcessedItems);
}
}
public void OnLinesService() {
for (int lineNumber : lines.keySet()) {
OnLineService(lineNumber, Integer.MAX_VALUE);
}
}
}
class Customer {
private int customerId;
private int lineNumber;
private int numItems;
public Customer(int customerId, int lineNumber, int numItems) {
this.customerId = customerId;
this.lineNumber = lineNumber;
this.numItems = numItems;
}
public int getCustomerId() {
return customerId;
}
public int getLineNumber() {
return lineNumber;
}
public int getNumItems() {
return numItems;
}
public void setNumItems(int numItems) {
this.numItems = numItems;
}
}
Supermarket Checkout โ
private Map<Integer, Customer> customers = new HashMap<>();
private Map<Integer, Queue<Customer>> lines = new HashMap<>();
public void OnCustomerEnter(int customerId, int lineNumber, int numItems) {
Customer customer = new Customer(customerId, lineNumber, numItems);
customers.put(customerId, customer);
if (!lines.containsKey(lineNumber)) {
lines.put(lineNumber, new LinkedList<>());
}
lines.get(lineNumber).add(customer);
}
public void OnBasketChange(int customerId, int newNumItems) {
Customer customer = customers.get(customerId);
int oldNumItems = customer.getNumItems();
customer.setNumItems(newNumItems);
if (oldNumItems > newNumItems) {
return;
}
Queue<Customer> line = lines.get(customer.getLineNumber());
line.remove(customer);
line.add(customer);
}
public void OnLineService(int lineNumber, int numProcessedItems) {
Queue<Customer> line = lines.get(lineNumber);
if (line.isEmpty()) {
return;
}
Customer customer = line.peek();
int numItems = customer.getNumItems();
if (numItems <= numProcessedItems) {
line.remove();
customers.remove(customer.getCustomerId());
System.out.println(customer.getCustomerId());
} else {
customer.setNumItems(numItems - numProcessedItems);
}
}
public void OnLinesService() {
for (int lineNumber : lines.keySet()) {
OnLineService(lineNumber, Integer.MAX_VALUE);
}
}
}
class Customer {
private int customerId;
private int lineNumber;
private int numItems;
public Customer(int customerId, int lineNumber, int numItems) {
this.customerId = customerId;
this.lineNumber = lineNumber;
this.numItems = numItems;
}
public int getCustomerId() {
return customerId;
}
public int getLineNumber() {
return lineNumber;
}
public int getNumItems() {
return numItems;
}
public void setNumItems(int numItems) {
this.numItems = numItems;
}
}
Supermarket Checkout โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Linkedin
Mobileum hiring Mobileum - Software Engineer - Algorithm/Data Structure in Bengaluru, Karnataka, India | LinkedIn
Posted 3:29:33 PM. Title : Software Engineer (Developer)Location : BangaloreWho we are ?We are leading provider ofโฆSee this and similar jobs on LinkedIn.
include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<int> minimalOperations(vector<string> words) {
vector<int> result;
for (const auto& word : words) {
int changes = 0;
for (int i = 1; i < word.size(); ++i) {
if (word[i] == word[i - 1]) {
++changes;
++i;
}
}
result.push_back(changes);
}
return result;
}
No Pairs Allowed โ
#include <vector>
#include <string>
using namespace std;
vector<int> minimalOperations(vector<string> words) {
vector<int> result;
for (const auto& word : words) {
int changes = 0;
for (int i = 1; i < word.size(); ++i) {
if (word[i] == word[i - 1]) {
++changes;
++i;
}
}
result.push_back(changes);
}
return result;
}
No Pairs Allowed โ
๐2
#include<bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> weights(N);
for (int i = 0; i < N; ++i) {
cin >> weights[i];
}
int total_weight = accumulate(weights.begin(), weights.end(), 0);
int min_weight = *min_element(weights.begin(), weights.end());
total_weight -= min_weight;
for (int i = 0; i < N; ++i) {
if (weights[i] != min_weight) {
cout << weights[i] - min_weight << " ";
}
}
return 0;
}
using namespace std;
int main() {
int N;
cin >> N;
vector<int> weights(N);
for (int i = 0; i < N; ++i) {
cin >> weights[i];
}
int total_weight = accumulate(weights.begin(), weights.end(), 0);
int min_weight = *min_element(weights.begin(), weights.end());
total_weight -= min_weight;
for (int i = 0; i < N; ++i) {
if (weights[i] != min_weight) {
cout << weights[i] - min_weight << " ";
}
}
return 0;
}
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Relx is hiring SDE Intern
For 2024/2025 Grads
Apply:
https://relx.wd3.myworkdayjobs.com/en-US/relx/job/Software-Engineering-Intern_R55486-2
For 2024/2025 Grads
Apply:
https://relx.wd3.myworkdayjobs.com/en-US/relx/job/Software-Engineering-Intern_R55486-2
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: Mercedes Benz
Role: Intern
Batch eligible: 2024 and 2025 grads only
Apply: https://jobs.mercedes-benz.com/job/379875/intern-2023.html
Role: Intern
Batch eligible: 2024 and 2025 grads only
Apply: https://jobs.mercedes-benz.com/job/379875/intern-2023.html
๐2