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
Coding & Algorithms
Software Engineer
Infosys
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

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
string processing
regular expressions
lookarounds
PII masking
edge cases
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported

Related Questions