Mask Account Numbers in Core Banking Statement Lines
Last updated: November 29, 2026
Quick Overview
Given a free-text statement or log line, replace every standalone run of 9 to 18 digits (an account number) with X characters except its last 4 digits, leaving shorter or longer digit runs untouched.
Infosys
November 29, 20260
0
0 solved
Given a free-text statement or log line, replace every standalone run of 9 to 18 digits (an account number) with X characters except its last 4 digits, leaving shorter or longer digit runs untouched.
A warm-up in the style of an Infosys campus online assessment, framed around Finacle-style banking statements and application logs that must not leak full account numbers. The grader checks careful string handling, boundary conditions, and whether you avoid masking digits that belong to a longer number.
What the Interviewer Expects
- Define precisely what counts as an account number (length range, digit boundaries)
- Keep the last 4 digits and preserve the original length
- Do not mask parts of longer or shorter digit runs
- Run in a single pass, linear in line length
- Handle empty input and lines with no matches
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you also mask numbers written with spaces or hyphens between groups?
- A 10-digit mobile number gets masked by this rule. How would you tell it apart from an account number?
- How would you apply this to a 50 GB log file without loading it into memory?
- Where in a logging pipeline should masking happen, and why not only at display time?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is one line of text. An account number is a maximal run of digits whose length is between 9 and 18. Replace all but its last 4 digits with X. Runs of 8 or fewer digits (OTPs, reference numbers...
High-Level Design
Scan for maximal digit runs. A regex does this cleanly if it is anchored with negative lookbehind (?<!\d) and lookahead (?!\d), so it never matches a slice of a longer run. Capture the head (5 to ...