RBC OA Interview Question: Validate a Bank Account Number

20 Views
No Comments

You are in charge of creating new bank accounts when a user signs up as an RBC customer. When creating a new bank account, a valid bank account number must be provided. A valid bank account number is an integer, exactly 14 digits long, and does not contain any repeating sequence of 4 or more consecutive digits. Write a function that checks a bank account number and ensures it is valid.

Input

account_number: A string

Output

Return true or false.

Example

account_number = "hello"
valid_account_number(account_number) # Output: False

This RBC interview question asks you to validate a bank account number during account creation. A valid number must be numeric, exactly 14 digits long, and must not contain any repeating sequence of 4 or more consecutive digits. A straightforward solution is to first verify the input format, then scan the string once while counting runs of identical digits and reject the number as soon as a run reaches length 4. The problem mainly tests string validation and linear-time traversal.

END
 0