Skip to content
Zeni Study
  • Pages
    • Learn Python In 7 Days
      • Day 1 : Variable + if/else
      • Day 2: Loops
      • Day 3 : Array + String
      • Day 4 — Functions
      • Day 5 — Dictionaries - Hashmap
      • Day 6 — Files & Errors
      • Day 7 — Mini Project & Programmer Thinking
    • Machine Coding:
      • icon picker
        Day 1 — Bank account + Wallet :
      • Day 2 : RateLimiter + seat booking
      • Day 3 : Library Management + Classroom Attendance System
      • Day 4 : Bank account and notification system.
      • Day 5 : Key-value and payment processor.
      • Day 6 : Discount engine + Seat booking( in depth)
      • Day 7: Parking lot System :
    • Machine coding extended:
      • Day 7.5 — Parking Lot (Constraint-Heavy Variant)
      • Day 8 : Order + Payment System
      • Day 8 — Extension Round (Mid-Interview Change)
      • Day 9 — Ticket Booking with Expiry (Simulated Time)
      • Day 9 — Extension Round (Seat Lock Ownership + Forced Unlock)
    • SQL + DB Thinking course
      • Day 1 — Tables, Rows & Thinking in Data
      • Day 2 — Relationships & Foreign Keys (Thinking in Connections)
      • Day 3 — Filtering, Aggregation & Answering Data Questions
      • Day 4 — JOINs (Combining Tables the Right Way)
      • Day 5 — Subqueries, EXISTS & NOT EXISTS (Thinking in Layers)
      • Day 6 — Indexes, Constraints & How Databases Think
      • Day 7 — Full SQL Interview Simulation (SDE-1 Ready)
      • Extended Day 1 — Core Business Systems (Deep Practice)
      • Extended Day 2 — Booking & Platform Systems (High-Depth Practice)
      • Extended Day 3 — Content & Learning Platforms (Capstone Practice)
    • LLD: Java
      • DAY 1 — Core Foundations (SDE-2 Level)
      • DAY 2 — State, Time & Domain Correctness
      • DAY 3 — Extensibility & Failure Handling (SDE-2 Core Signal)
      • DAY 4 — Concurrency, Scheduling & Consistency (SDE-2 Critical)
      • DAY 5 — Workflow Design & Config-Driven Systems (SDE-2+)
      • DAY 6 — Eventing & Usage-Based Systems (Advanced SDE-2)
      • DAY 7 — Interview Simulation (Hard, Production-Grade)
      • Hidden Edge Cases Interviewers Expect (Day-wise)
      • Detailed Testing file:
    • Assignment:
      • If else Practice Set

Day 1 — Bank account + Wallet :

Day 1 — Classes, Objects & State (Machine Coding Foundations)

🎯 Day 1 Objective (Say This Clearly)

By the end of Day 1, the candidate should be able to:
Read a problem statement with given class & method signatures
Correctly place data inside objects
Implement logic inside methods without guessing
Maintain and update object state
Pass basic machine-coding style test cases
Today is about where data lives and how methods change it.

1️⃣ Teaching Script — What to Say (Structured)

Start with This Truth

“In machine coding rounds, you are not judged on elegance. You are judged on whether your code works exactly as required.”
“Most candidates fail because they don’t know:
What should be a class
What should be a variable
Where state should be stored”
Today fixes that.

2️⃣ Core Idea of OOP (Only What Is Needed)

One Sentence Definition

A class is a blueprint. An object holds data and behavior together.

Real-World Analogy (Use This)

Think of a bank account:
Balance belongs to one account
Deposit affects that account only
Withdraw affects that account only
That’s an object with state.

3️⃣ Small Code to See & Understand (No Abstraction)

Example 1 — Minimal Class

class Counter:
def __init__(self):
self.value = 0

def increment(self):
self.value += 1

How to Think (IMPORTANT)

self.value is state
It lives inside the object
Every object has its own copy
c1 = Counter()
c2 = Counter()

c1.increment()
print(c1.value) # 1
print(c2.value) # 0
🧠 Machine coding expects you to reason like this.

4️⃣ Small Practice (Warm-up, Mandatory)

Task (Do This Before Problems)

Implement this class:
Class Name: SimpleCalculator

Methods:
- add(a, b) → returns sum
- subtract(a, b) → returns difference
Rules:
No printing
Just return values
No global variables
👉 This is just to get comfortable with syntax.

5️⃣ Key Rules for Machine Coding (Day 1 Rules)

Read this carefully. These are non-negotiable.
Do not change method signatures
Do not add extra parameters
Store state inside self
Return values — don’t print
Assume tests will call methods directly

6️⃣ Main Problem 1 — Bank Account (State-Based)

Problem Statement

You are given a class BankAccount.
Each BankAccount object represents one user’s bank account.

Class Definition (DO NOT MODIFY)

class BankAccount:
def __init__(self, account_number: str, balance: int):
pass

def deposit(self, amount: int) -> bool:
pass

def withdraw(self, amount: int) -> bool:
pass

def get_balance(self) -> int:
pass

Requirements (Very Strict)

__init__
Store account_number
Store initial balance
deposit(amount)
If amount <= 0 → return False
Otherwise:
Add amount to balance
Return True
withdraw(amount)
If amount <= 0 → return False
If amount > balance → return False
Otherwise:
Deduct amount from balance
Return True
get_balance()
Return current balance

Example Usage (Tests Will Be Similar)

acc = BankAccount("A123", 1000)

acc.deposit(500) # True
acc.withdraw(200) # True
acc.withdraw(2000) # False
acc.get_balance() # 1300

What This Problem Tests

Correct use of __init__
Correct state mutation
No shared/global state
Correct return values

7️⃣ Main Problem 2 — Digital Wallet (Slightly Trickier)

Problem Statement

You are given a class Wallet.
A wallet starts empty and stores money in integer units.

Class Definition (DO NOT MODIFY)

class Wallet:
def __init__(self):
pass

def add_money(self, amount: int) -> bool:
pass

def spend_money(self, amount: int) -> bool:
pass

def get_money(self) -> int:
pass

Requirements

add_money(amount)
If amount <= 0 → return False
Otherwise:
Increase wallet balance
Return True
spend_money(amount)
If amount <= 0 → return False
If amount > balance → return False
Otherwise:
Deduct amount
Return True
get_money()
Return current wallet balance

Hidden Edge Case (Important)

Multiple method calls will be made
Balance must be preserved correctly

8️⃣ No-Guess Hint Section (Read Only If Stuck)

Use self.balance
Initialize balance in __init__
Do not use class variables
Every object should behave independently
Tests will create multiple objects

9️⃣ Evaluation Checklist (Use This to Judge Solution)

A solution is correct if:
✅ No syntax errors
✅ All methods return correct values
✅ Balance updates correctly
✅ Edge cases handled
✅ No print statements
✅ No global variables

🔟 Reflection (Candidate Must Answer)

Answer in words:
Where does balance live?
Why do we use self.balance instead of a normal variable?
What happens if two Wallet objects exist?
What breaks if balance is global?

⭐ Day 1 Golden Rule

In machine coding, wrong place for state = guaranteed failure.

🧪 Day 1 — Test File (DO NOT MODIFY STUDENT CODE)

👉 Instruction to Candidate
Implement the required classes in solution.py. Do NOT change class names or method signatures. Run this file to verify correctness.

📁 Expected Folder Structure

day1/
├── solution.py # Candidate writes code here
└── test_day1.py # Provided test file (below)

📄 (Skeleton Given to Candidate)

 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.