Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java to solve this algorithm challenge: Problem Description There are a lot of horses in the yard, and we want to count how many

Use Java to solve this algorithm challenge:

Problem Description

There are a lot of horses in the yard, and we want to count how many there are. Unfortunately, we've only got a recording of the sounds from the yard. All the horses say "neigh". The problem is they can "neigh" many times. The recording from the yard is sadly all mixed together. So, we need to figure out from the overlapping sounds how many horses there could be.

For example, we've got two horses in the yard, and we hear this "neigneighh". From this recording, we can successfully deduce there are 2 horses. Another example is "neighneigh". From this example, we can only tell there is one horse in the yard.

As an additional complexity, our recording might not be perfect. If it's a bad recording, we should give "Invalid" as the response.

The input will be given as a string on one line. The output should be printed on it's own line.

Sample Input

nenigehnieighgh

Sample Output

2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Recognize the power of service guarantees.

Answered: 1 week ago