Be the first user to complete this post

  • 0
Add to List
Medium

439. Determine the given routing number belong to which bank

Objective: Given the banks and range of routing numbers for each bank. You have given a routing number, write a program to determine which bank it belongs to.

Input: Given a list of routing ranges for each bank, with a start number, end number, and bank name. For instance, range = [1001, 1005, BOFA] has to read as routing numbers from 1001 to 1005 belong to bank BOFA.

Example-

Input: [[123400,123500, BOFA], [123600,123700, WELLS FARGO], [12538,125480, GCU], [126100,126500, CHASE]]

Routing number: 123650 belongs to bank WELLS FARGO
Routing number: 12540 belongs to bank GCU
Routing number: 126050 does not belong to any bank.

Approach:

Idea is to sort the given ranges as per the start number and then find the largest range with a start is smaller than given routing number. Then check if the routing number is in between the start and end of that largest range. To construct the TreeMap map with start number as key and range as value. Then map.floorEntry(routingNumber) will return the largest entry where the start number is smaller than routingNumber. Now, will check if routingNumber falls in the range of start and end of the largest entry.

Output:

Input: [[123400,123500, BOFA], [123600,123700, WELLS FARGO], [12538,125480, GCU], [126100,126500, CHASE]]
Given routing number: 123650 belongs to bank WELLS FARGO
Given routing number: 12540 belongs to bank GCU
Given routing number: 126050 does not belong to any bank.


Reference: https://www.careercup.com/question?id=5669049954992128