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 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 As and at least two Bs and therefore
ABBA will be contained in them. In the next examples we see that BARBER has two Bs but only one A
and AKROBAT has two As but only one B ABBA will therefore not be contained in them.
Create the method public static boolean containedString 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 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 to count the number of times
you have seen a letter. For example, countintA will increment count by one.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
