I am having confusion on this particular question there is list of questions on my mind. expecting answer with full details explanation.
This is the sample code. and expected output is function should print Shop name with item name where item should be maximum.
public static void print(List<Shop> shops,List<Item>items, List<Inventory>inventories) {
for (Shop shop : shops) {
int maxQty = -1;
String shopName;
int id = 0;
for (Inventory inventory : inventories) {
if(inventory.getMaxQty()>= maxQty) {
maxQty = inventory.getMaxQty();
shopName = inventory.getShop().getName();
}
}
for (Item item : items) {
if(item.getShop().getId() == id) {
System.out.println("Shop name is "+ item.getShop().getName() +" Item name is "+ item.getName() +" and maxQty is "+ maxQty);;
}
}
}
}
So My questions is
- What this function should print(is this function given expected output)?.
- What is the time complexity of given function and how to optimize code for better time complexity.
3.What is the right class hierarchic?
4.Can we apply any design pattern? If yes so please explain in details.
And last first time i am using this platform for my doubts, So forgive me if i did any mistake.
Thanks in advanced for help.
Aucun commentaire:
Enregistrer un commentaire