Skip to content

Target Coding Questions - DSA Problems & Solutions

Practice Target placement paper coding questions with detailed solutions. Access Target OA coding problems in Java, Python.

This page contains Target coding questions from Target OA placement papers with detailed solutions.

Target OA Coding Section:

  • Problems: 2-3 coding problems
  • Time: 90 minutes
  • Languages: Java, Python
Q1: Design an inventory management system with stock tracking.

Solution (Java):

class InventoryManager {
Map<String, Integer> inventory = new HashMap<>();
public void addStock(String productId, int quantity) {
inventory.put(productId, inventory.getOrDefault(productId, 0) + quantity);
}
public boolean sellProduct(String productId, int quantity) {
int currentStock = inventory.getOrDefault(productId, 0);
if (currentStock >= quantity) {
inventory.put(productId, currentStock - quantity);
return true;
}
return false;
}
public int getStock(String productId) {
return inventory.getOrDefault(productId, 0);
}
}

Time Complexity: O(1) for all operations


Practice Target coding questions regularly!