Spring Boot Interview Question: Batch Transaction Compaction
Code examples, interview, design and more ...
Background
You are working on a Spring Boot–based payment processing system.
The system receives batches of transaction IDs from upstream services.
Each batch is represented as an integer array.
A value of
0represents an invalid or failed transactionA non-zero value represents a valid transaction
Before forwarding the batch to a downstream settlement service, the system must:
Process all valid transactions first
Move all invalid transactions (
0) to the endPreserve the original order of valid transactions
Perform the operation in-place to avoid extra memory usage
Task
Implement a Spring Boot service that:
Accepts a batch of transactions via a REST endpoint
Reorders the batch according to the rules above
Returns the processed batch
For example,
Request Body:
[0, 1045, 0, 2099, 3301]
Response:
[1045, 2099, 3301, 0, 0]📢 Get actionable Java/Spring Boot insights every week — from practical code tips to real-world use-case based interview questions.
Join 5500+ subscribers and level up your Spring & backend skills with hand-crafted content — no fluff.
First 100 paid subscribers will get the annual membership at $50/year ( 67 already converted to paid, 33 remaining )
Not convinced? Check out the details of the past work
Solution
Endpoint:
Logic:
Create a new array
First, copy all valid transactions
Then append non-valid transactions
Return the new array





