Flipkart Machine Coding Round - Dec 2023

Anonymous User
268
Dec 01, 2023
Dec 03, 2023
Flipkart Daily. 
Description: 
Flipkart wants to build a product to deliver groceries and daily essentials by next morning. Users can search for items from inventory with some filters and will be allowed to place an order only if He/She has enough in the wallet. 
Features: 
1. Define price for the items. SetPrice(category, brand, price) 
2. Add item to inventory. AddItem(category, brand, quantity) 
(category → milk, bread & brand → Amul milk or Britannia bread) 
3. Add/remove item to user’s cart. 
4. Get current user cart info. 
5. Checkout -  This places the order directly using the wallet amount. 
6. Define wallet per user, ability to add money to Wallet.
Bonus: 
7. Search items in inventory via using multiple filters like price, brand, category and can perform search with multiple filters. 
search(brand,price), search(category, price), search(brand,category)... 
8.Concurrency Scenario: Code should handle potentially concurrency use cases.


Other Details: 
1. Do not use any database or NoSQL store, use in-memory store for now. 2. Do not create any UI for the application. 
3. Write a driver class for demo purposes. Which will execute all the commands at one place in the code and test cases. 
4. Start with min 5 items with more quantities varying from 0-30 
5. Assume that only one active session will be there for customers. 
Expectations: 
Create the sample data yourself. You can put it into a file, test case or main driver program itself or use STDIN. You should be able to modify the test cases when asked.
Code should be demo-able. Either by using a main driver program or test cases. 
Code should be modular. Code should have basic OO design.
Code should be extensible. Wherever applicable, use interfaces and contracts between different methods. It should be easy to add/remove functionality without re-writing the entire codebase. 
Code should handle edge cases properly and fail gracefully. 
Code should be legible, readable and DRY. 
You can choose to show the final output on STDOUT or write to a file.
We expect you to store all data in memory. Usage of the database to store the contents is not allowed

Guidelines:


Make sure you get any clarification you need before starting the implementation.
Please discuss the solution with an interviewer. 
Please do not access internet for anything EXCEPT syntax
You are free to use the language of your choice
All work should be your own
Overall time: 90 mins
Test cases: (You need not follow the same method signatures and output)                
1. Add/Update Item (brand, category, price) 
2. Add inventory (category,brand, quantity) 
3. Add user (“Name”,”Address”,”Wallet Amount”)
4. Search (“brand”,”category”)  - expected response  <brand, category, price, remaining_inventory_count> {Bonus} 
5. Add to cart(user, category, brand, quantity) 6. Get cart info(user) 
7. Remove from cart 
8. Checkout
Sample input/output 
# AddItem(<item_brand>, <item_category>, <item_price>)
AddItem(Amul, Milk, 100) 
AddItem(Amul, Curd, 50) 
AddItem(Nestle, Milk, 60) 
AddItem(Nestle, Curd, 90) 
# AddInventory(<item_brand>, <item_category>, <units>)
AddInventory(Amul, Milk, 10) 
AddInventory(Nestle, Milk, 15) 
AddInventory(Nestle, Curd, 10) 
AddInventory(Amul, Milk, 10) 
AddInventory(Amul, Curd, 5) 
# Final View Inventory :
Amul - > Milk -> 20 
Amul -> Curd -> 5 
Nestle -> Milk -> 15 
Nestle -> Curd -> 10 

#AddUser(<Name>,<Address>,<Wallet Amount>)
AddUser(Jhonny, ”Flipkart Bellandur, Bangalore 560068”,  600)
 AddUser(Naruto, ”BTM Layout, Bengaluru, 560042”, 500) 
AddUser(Goku, ”Vijay Nagar, Indore, MP”,  3000) 
# AddToCart(<User_Name>, <item_category>, <item_brand>, <units>)
AddToCart(Jhonny, Milk, Nestle, 5) 
UpdateItem(Nestle, Milk, 5) 
AddToCart(Goku, Milk, Nestle, 10) 
# GetCart(<User_Name>)
GetCart(Goku) 
Nestle -> Milk - > 10 → Total Price  50  
 GetCart(Jhonny) 
Nestle -> Milk -> 5 -> Total Price : 25 GetCart(Naruto)
Empty Cart 
# expected response  <brand, category, price, remaining_inventory_count>
SearchItems([Nestle]) 
Nestle -> Curd-> 90 -> 10 
SearchItems([Nestle, Amul], [Curd]) 
Amul -> Curd -> 50 -> 5 
Nestle -> Curd -> 90 -> 10 
SearchItems([Nestle], [Curd, Milk, Paneer]) Nestle -> Curd -> 90 -> 10 
Nestle -> Milk -> 60 -> 0 

# Checkout(<Name>)
Checkout(Goku)
-> Successful checkout , new wallet amount: 2950
Checkout(Jhonny)
-> Successful checkout , new wallet amount: 575
Checkout(Naruto)
-> No order to checkout
Note: in case the wallet amount is less than cart total amount, checkout fails
ALL THE BEST
Comments (2)