HV
home / chargebee / other

SQL, OOP, Puzzles & Behavioral Questions

Chargebee interviewers spend as much time on fundamentals and communication as on raw coding — SQL window functions, OOP/SOLID reasoning, brain teasers, and structured behavioral answers all show up.

Given an employee table with a manager_id self-reference, list each employee with their manager's name.

SELECT e.name AS employee, m.name AS manager
FROM employee e
LEFT JOIN employee m ON e.manager_id = m.id;
-- LEFT JOIN (not INNER) so employees with no manager (e.g. the CEO) still appear

Rank employees by salary within each department (ties should share the same rank).

SELECT name, department, salary,
       DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dept_rank
FROM employee;
-- PARTITION BY resets the ranking per department
-- DENSE_RANK (not RANK) avoids gaps after a tie, e.g. 1,1,2 instead of 1,1,3

Find everyone who has been vaccinated exactly n doses (n ≥ 0), including people with zero doses.

SELECT p.id, p.name, COUNT(v.id) AS doses_taken
FROM person p
LEFT JOIN vaccination_record v ON v.person_id = p.id
GROUP BY p.id, p.name
HAVING COUNT(v.id) = :n;
-- LEFT JOIN + COUNT(v.id) is required (not COUNT(*)) so n = 0 correctly matches
-- people with zero matching vaccination_record rows

OOP Fundamentals With a Real-Life Example

Encapsulation A Subscription class exposes cancel() / upgrade() methods but keeps status and current_period_end private — callers can't set an invalid status directly.
Abstraction A PaymentGateway interface exposes charge(amount) without callers knowing whether it's calling Stripe or Razorpay underneath.
Inheritance Car, Bike, Truck all extend an abstract Vehicle, inheriting shared fields (license_plate) while overriding requiredSpotSize().
Polymorphism ParkingLot.allocate(vehicle) calls vehicle.requiredSpotSize() — the correct behavior runs based on the actual runtime type, no if/else chain needed.

SOLID Principles

S — Single Responsibility InvoiceGenerator computes amounts; EmailService sends receipts. Don't let one class do both — a billing logic change shouldn't risk breaking email formatting.
O — Open/Closed Adding Truck to the parking lot means adding a new class, not editing ParkingLot's core allocation logic.
L — Liskov Substitution Any Vehicle subtype must be usable wherever Vehicle is expected — a Bike shouldn't throw an exception when asked for requiredSpotSize().
I — Interface Segregation Don't force every PaymentMethod to implement refund() if some (e.g. cash) genuinely can't support it — split into smaller interfaces.
D — Dependency Inversion Subscription depends on the PaymentGateway interface, not a concrete StripeClient — makes swapping providers or mocking in tests trivial.

Multithreading & Collections (Java-flavored, language-agnostic ideas)

Race condition Two threads incrementing a shared counter without synchronization can lose updates — guard with a lock, atomic type (AtomicInteger), or use immutable/thread-confined data instead.
Thread pool over raw threads Creating a new thread per request doesn't scale — use a bounded ExecutorService/thread pool so load is throttled instead of exhausting memory.
Concurrent collections Prefer ConcurrentHashMap over synchronizing a plain HashMap manually — finer-grained locking gives much better throughput under contention.
Deadlock Happens when two threads each hold a lock the other needs. Avoid by always acquiring locks in a consistent global order.
Classic 9 Balls, 1 Scale — Find the Lighter One

You have 9 balls, all identical except one that is lighter. Using a balance scale, what's the minimum number of weighings to find the odd ball?

Follow-up asked in the actual interview: what if you don't know whether the odd ball is heavier or lighter?

Answer: 2 weighings for the original version.

Split into groups of 3, 3, 3:
1. Weigh group A (3 balls) vs group B (3 balls).
   - If balanced → the odd ball is in group C. If A is lighter → it's in A. If B is lighter → it's in B.
   - Now you have 3 candidate balls.
2. Weigh 2 of those 3 balls against each other.
   - If balanced → the 3rd ball is the odd one.
   - Otherwise → the lighter side is the odd ball.

Follow-up (odd ball could be heavier OR lighter): still solvable in 3 weighings
for up to 12 balls (a classic generalization) — with exactly 9 balls, 2 weighings
still suffice using the same 3/3/3 split, since the imbalance direction from
weighing 1 tells you which group AND whether you're looking for heavier or lighter.
Classic Find the 3 Fastest Horses (25 Horses, Track Fits 5 at a Time)

25 horses, no stopwatch — only relative finishing order per race, and the track only fits 5 horses at once. Find the top 3 fastest horses in the minimum number of races.

Answer: 7 races minimum.

1. Races 1–5: Split into 5 groups of 5, race each group. (5 races)
   Now you know the ranking within each group.
2. Race 6: Race the winners of all 5 groups against each other.
   The overall winner of race 6 is the fastest horse overall.
3. Eliminate: the 4th and 5th place group-winners' entire groups are out
   (they can't be in the top 3 — 3+ horses in those groups already
   proven slower than a horse that isn't even the fastest).
   The 2nd/3rd place group-winners' bottom horses are also out.
4. Race 7: Race the remaining candidates for 2nd/3rd place overall —
   this includes the 2nd/3rd place finishers from the winner's group,
   the top 2 from the 2nd-place group-winner's group, and the top 1
   from the 3rd-place group-winner's group (5 horses max).
   The top 2 of this race are the overall 2nd and 3rd fastest.
Walk me through your professional journey / highlight your past experience.

Structure chronologically but end with *why this role, now* — tie your trajectory directly to what Chargebee's role needs.

How do you handle incidents and difficult production situations?

Use a concrete STAR example: detection → mitigation (stop the bleeding) → root cause → prevention (postmortem action items). Emphasize communication during the incident, not just the fix.

What happens when a crash only appears once every three days?

Talk about improving observability first (structured logs, correlation IDs, sampling traces) rather than guessing — intermittent bugs need better signal before a fix, not more code changes.

How do you manage conflict with a teammate or manager?

Show you address it directly and early, focus on the technical/process disagreement (not personal), and escalate constructively only after a 1:1 conversation fails.

What would your manager say about you if I called them right now?

Pick 2 concrete traits backed by an example each — generic answers ('hard worker') don't land. Ownership + how you handle feedback are strong choices.

Why join Chargebee when you already have another offer?

Anchor on something specific to Chargebee's domain (subscription billing at scale, the engineering challenges of correctness in money-handling systems) — avoid generic 'good culture' answers.