Question: Exercise 1 0 ( Contained ) In this exercise, we say that a string is contained in another string, if every letter in the first

Exercise 10(Contained)
In this exercise, we say that a string is contained in another string, if every letter in the first string occurs at
least as many times in the second string, but not necessarily in the same order. Some examples:
The string ABBA is contained in ABBABBA, BARBARER, and RHARBRABRA.
The string ABBA is not contained in BARBER, or ACROBAT.
In the first examples, we see that all the words contain at least two A's, and at least two B's, and therefore
ABBA will be contained in them. In the next examples we see that BARBER has two B's but only one A,
and AKROBAT has two A's but only one B. ABBA will therefore not be contained in them.
Create the method public static boolean contained(String a, String b), which tells whether the string a
is contained in the string b . That is, the method should return true if a is contained in b , and false otherwise.
You can, if you wish, assume that both strings only have capital letters (A-). There is no limit to how long
the words can be.
The method must be designed so that it is relatively effective. One of the tests will measure
efficiency on large strings.
Hint: If you turn a letter into an integer, you can use a table of length 256 to count the number of times
you have seen a letter. For example, count[(int)'A']+=1 will increment count[65] by one.
Exercise 1 0 ( Contained ) In this exercise, we

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!