Oracle VO Interview Question: Term Finder

14 Views
No Comments

Given an array of strings (terms), find the number of occurrences of each term in a string. You need only fill out the Count method.

Parameters:

  • Use any data structures available to you, including ones you create.
  • The term count map must be ordered in the order of the terms string array (for example, fizz first, buzz second, fizzbuzz third).
  • Duplicate terms in the array are not allowed (assume a process has previously de-duped the terms in the array).
  • Cannot use any regular expression API/libraries.
  • Blank strings (i.e. "") and null should be handled and returned with all terms set to zero.
  • No exceptions should be thrown or need to be handled.

Return a map of each term to its occurrence count in the input string.

This problem asks you to count how many times each term appears in an input string, while preserving the original order of the terms in the returned map. A practical solution is to iterate through the terms and count matches without using regular expressions, then store the results in an order-preserving map such as LinkedHashMap. Special cases matter here: if the input string is empty or null, every term should map to 0.

END
 0