Skip to main content
All Questions

Add PIN validation to an existing Spring Boot card PATCH endpoint.

Unlock detailed company stats for this questionUpgrade

In an existing Spring Boot card application, add validation to the PATCH endpoint that updates a card's PIN. Rules: the PIN must be exactly four digits, numeric only, with no repeating digits anywhere (1213 is invalid even though the repeats are not adjacent), and a positive value, while preserving leading zeros.

The repository contains a card model with multiple fields, a controller, and a repository backed by H2 through JPA. The card model already stores the PIN as an int and the controller accepts it directly as an int parameter, so leading zeros require changing the representation to String across the controller, service/validation, card model and persistence mapping. Valid input updates the PIN preserving leading zeros; invalid input is rejected without modifying the stored card. Verify with tests covering the validation rules, leading-zero handling and unchanged state after rejected updates.

Format · Roughly one hour on HackerRank with an AI assistant and an existing Java Spring Boot + H2 + JPA repository.

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.