Flipkart | SDE 2 | Machine coding problem

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-07-28Added By Anonymous
Source: Link

Company: Flipkart
Role: SDE 2
Interview Stage: Onsite
Location: unknown
Year: unknown

Original Post Content:

Flipkart Mini-Wallet

You are tasked with designing a Flipkart Wallet system. This system allows users to perform various operations related to their wallet, such as loading money, sending money, and managing fixed deposits. The following are the requirements and assumptions for the system.

Requirements:

1.User RegistrationUsers need to register on Flipkart to use this wallet.
2.Deposit Money (Add money to wallet)Users can load money into their wallet via various sources (Credit Card, Debit Card, UPI, etc.).The minimum amount of load money should be greater than 0.No need for integration from sources; assume the operation is always successful.Rules on deposit based on instrumentCredit Card: 3 transactions per Credit Card allowedUPI: 1000 Rs max per transaction allowedDebit Card: Transaction penalty of 1 Rs after 3 transactions with debit card.Should be made configurable and extensible.If the above conditions are violated, we should block the transaction.
3.Send MoneyUsers can send money to other users from their wallet.The minimum amount for a transaction is always greater than 0.Users must have sufficient balance in their wallet to complete transactions
4.Fixed Deposit (FD):Users can block a certain amount as a fixed deposit from the wallet. This amount will be reduced from the wallet balance.A user can have one deposit for a particular deposit type at a time.Users should have the ability to dissolve the FD. After doing so, the FD amount should be unblocked for regular transactions.
5.Wallet Balance:Users can fetch their wallet balance at any point in time. This should consider both credit & debit type transactions.
6.Transaction History:Users can get their transaction history sorted by:Amount ("amount")Transaction Date Time ("time")Users can filter their transaction history based on:Credit or Debit Amount

BONUS
The transactions (user to user) will be eligible for cashback if they meet their respective criteria. Let's say criteria can be, based on "after each 5 transactions" or "With 0.5 probability for each transaction", provide X amount as cashback and added to the user's wallet.

Capabilities
Below are various functions that should be supported with the necessary parameters passed.
These are just suggestions, the signatures can be altered as long as the functionalities are provided.

  • registerUser() - Register user to use wallet
  • topUpWallet() - Add money to the wallet for users with any of the resources.
  • fetchBalance() - Fetch balance available in the wallet for user
  • sendMoney() - Send money to the user. Each money transfer will be considered as a transaction.
  • getTransactions (filter, sorter) - fetches transactions history based on filter and sorting criteria
  • createDeposit() - Add money from wallet to deposit of the type mentioned.
  • bookDeposit() - Dissolves amount present in deposit and adds the amount to wallet

Expectations

1.Create the sample data yourself. You can put it into a file, test case or main driver program or via Unit tests itself.
2.Database integration is not required. You should store the data in memory using a language-specific data structure.
3.The code should be demo-able. Either by using the main driver program or test cases.
4.The code should be modular. The code should have the basic OO design. Please do not put all responsibilities of one class into another.
5.The code should be extensible. Wherever applicable, use interfaces and contracts between different methods. It should be easy to add/remove functionality without rewriting the entire codebase.
6.The code should handle edge cases properly and fail gracefully.
7.The code should be legible, readable and DRY.

Implementation

1.Provide a clear, modular design of the classes and their interactions.
2.Implement the classes and methods in Java spring boot.
3.Include unit tests for key functionalities like loading money, sending money, blocking FD, dissolving FD, fetching balance, and getting transaction history.

Test Cases

1.fetchBalance("Bob")User Bob is not registered
2.registerUser("Bob")User Bob is registered
3.registerUser("Jack")User Jack is registered
4.topUpWallet("Bob", "CC", 1000)Bob's wallet has credit with 1000 Rs successfully
5.topUpWallet("Bob", "UPI", 100)Bob's wallet has credit with 100 Rs successfully
6.fetchBalance("Bob")Bob's wallet has 1100 Rs amount
7.topUpWallet("Bob", "UPI", 2000)Top up is not allowed as the amount crosses UPI allowed limit.
8.registerUser("Alice")User Alice is registered
9.topUpWallet("Alice", "CC", 100)Alice's wallet has credit with 100 Rs successfully
10.fetchBalance("Alice")Alice's wallet has 100 Rs amount
11.topUpWallet("Alice", "CC", 200)Alice's wallet has credit with 200 Rs successfully
12.topUpWallet("Alice", "CC", 100)Alice's wallet has credit with 100 Rs successfully
13.topUpWallet("Alice", "CC", 100)Not allowed as 3 transactions already happened with the credit card.
14.sendMoney("Bob", "Alice", 1250)Bob doesn't have sufficient amount to transfer 1250 Rs
15.sendMoney("Bob", "Alice", 250)Bob has transferred 250 Rs amount to Alice
16.sendMoney("Alice", "Bob", 50)Alice has transferred 50 Rs amount to Bob
17.sendMoney("Bob", "Jack", 100)Bob has transferred 100 Rs amount to Jack
18.fetchBalance("Bob")Bob's wallet has 800 Rs amount
19.createDeposit("Bob", "FD", 500)Bob has created an FD of 500
20.fetchBalance("Alice")Alice's wallet has 300 Rs amount
21.fetchBalance("Bob")Bob's wallet has 300 Rs amount
22.fetchBalance(" Jack")Jack's wallet has 100 Rs amount
23.getTransactions ("Bob", "Credit", "amount")Bob -> Jack: 100 RsBob -> Alice: 250 RsBob -> FD : 500 RsBob -> Alice: 1250 Rs
24.getTransactions ("Bob", "Debit", "time")Alice -> Bob: 50 Rs
25.bookDeposit("Bob", "FD")Bob has dissolved an FD of 500
26.fetchBalance("Bob")Bob's wallet has 800 Rs amount
Comments