Trains the technique from
LeetCode 299Bulls and CowsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A practice keypad holds a stored code and grades each attempt of the same length. Both are strings of digits, and digits may repeat in either of them.
The keypad grades an attempt with two counts:
loose. Each surviving code digit can back at most one attempt digit.Return the grade as the string "locked/loose", for example "2/1" for two locked and one loose. Both numbers are written in decimal with no padding.
Example 1
Only the last position agrees, giving locked = 1. The leftover code digits are 4, 5, 0 and the leftover attempt digits are 0, 4, 5, which pair up completely, so loose = 3.
Example 2
Position 1 agrees on the digit 2, so locked = 1. What is left of the code is 2, 3, 3 and what is left of the attempt is 3, 2, 2. One 2 and one 3 can be paired, and the attempt's spare 2 has no partner, so loose = 2.
Example 3
Position 0 agrees, so locked = 1. The leftover code digits are 1, 1 and the leftover attempt digits are 2, 3, which share nothing, so loose = 0.
Example 4
Both positions agree, so locked = 2 and nothing is left over.
Example 5
No position agrees and no digit value appears in both strings.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def feedback(code: str, attempt: str) -> str:public String feedback(String code, String attempt)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.