Code · Interview problems
Interview problems
Practical, multi-part coding questions like the ones asked in real rounds: parsing, pricing, routing, rate limiting. Each one has the full question, and every part is solved in Java.
github.com/aayushi-kunwar13/sde2-code-practice ↗Problems · 15
Bulls and Cows
MediumGiven a secret number and a guess of the same length, return the hint "xAyB": x = digits right in value and position (bulls), y = digits right in value but in the wrong position (cows).
Payment Parser
EasyA payment is "paymentId,amount,Paying off: invoiceId" and invoices are "invoiceId,dueDate,amount". Return "<paymentId> pays off <amount> for <invoiceId> due on <dueDate>", or NOT_FOUND. (First attempt; the full 3-part version is question7.)
Rank Teams by Votes
MediumEach voter ranks all teams (a string like "ACB"). Order teams by the most 1st-place votes; break ties by 2nd-place votes, and so on; if still tied, alphabetically.
Snake and Ladder
MediumModel a Snake and Ladder game: an n x m board with snakes (head to tail) and ladders (start to end), players with positions, and a 1-6 dice. (Entity notes only so far.)
Text Justification
HardPack words greedily into lines of exactly maxWidth characters. Spread extra spaces as evenly as possible (extra ones go to the left gaps); the last line and one-word lines are left-justified.
Token Bucket Rate Limiter
MediumImplement allowRequest() for a rate limiter: a bucket holds up to capacity tokens and refills at refillPerSec; each request spends one token or is rejected.
Currency Conversion
MediumConvert an amount using FROM:TO:RATE pairs: direct rate, then through other currencies, then the shortest route.
Accept-Language Parser
MediumReturn the server-supported languages in the order an Accept-Language header prefers them, then with q= weights.
Idempotent Request Replay
MediumReplay stored responses for repeated idempotency keys, then with key expiry (TTL), then rejecting conflicting retries.
Volume (Tiered) Pricing
MediumPrice a quantity with all-units tiers, then graduated tiers, then find the most units a budget buys.
Flight Cost Calculation
MediumCheapest flight from SRC:DST:AIRLINE:COST entries: direct, one stop, then any stops with route and airlines.
Spotting an Error Spike
HardAlert when a merchant has 5+ errors in 30s, then relative to successes, then with TRIGGER/RESOLVE events.
Payment Invoice Matching
MediumMatch a payment to an invoice by memo, then by equal amount (earliest due date), then within a forgiveness amount.
Task / Sub-task Hierarchy
MediumPrint tasks by date with their sub-tasks underneath, using |- and \- tree prefixes.
Merchant Payout Scheduler
EasyGroup transactions into the next payout day for a payout interval and print the totals per day.