Last Updated: 2 Jun, 2021

Help Bob Out!

Easy
Asked in company
Bottomline Technologies

Problem statement

Bob has just turned 18 years old and has opened a Bank account. However, since he has just opened his bank account he is not very experienced about the working of banks, therefore he asks for your help. Bob wants to know whether the IFSC Code given by the bank is valid or not, can you help him?

A valid IFSC (Indian Financial System) Code must be of the following format:-

1) The string should be 11 characters long.

2) The first four characters of the IFSC Code should be upper case alphabets.

3) The fifth character should be 0.

4) The last six characters should be alphanumeric.

Input Format:
The first line contains an Integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.

The first line of each test case consists of a string ‘S’ which denotes the IFSC Code.
Output Format:
For each test case print ‘True’ if the IFSC code is valid otherwise print ‘False’.

Output for each test case will be printed in a separate line.
Note:
You are not required to print anything, it has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 10
1 <= |S| <= 100

Time Limit: 1 sec

Approaches

01 Approach

To check whether the string is a valid IFSC Code or not we can check every character of the string explicitly and check whether the string is in the correct format or not.

 

Algorithm:-

  1. If the length of the string is not equal to 11, return False.
  2. Else, iterate from the first index to the fourth index.
    1. Check whether the ASCII values of the characters lie between 65 - 90. If not, return False.
  3. If yes, check whether the fifth character is 0 or not. If No return False.
  4. If yes, iterate from the fourth index to the eleventh index.
    1. Check whether the ASCII values of the characters lie between 65 - 90 or 48 - 57. If not, return False. If yes, return True.

02 Approach

To check whether the string is a valid IFSC Code first create a regular expression and match the given string with the regular expression.

 

The regular expression should be constructed as {^[A - Z] {4} 0 [A - Z0 - 9] {6} $} :-

 

  1. ^ -> represents the beginning of the string.
  2. [A - Z] {4} -> represents the first four characters of the string should be upper case alphabets.
  3. 0 -> represents the fifth character should be 0.
  4. [A - Z0 - 9] {6} ->represents the last six characters of the string should be alphanumeric.
  5. $ ->represents the ending of the string.

 

Algorithm:-

  1. If the length of the string is not equal to 11, return False.
  2. Else, define a regular expression {^ [A - Z] {4} 0 [A - Z0 - 9] {6} $}.
  3. Check whether the string matches the regular expression.
  4. If yes, return ‘True’, else ‘False’.