Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given a C++ string consisting of any lowercase alphanumeric characters ('a'-'z', '0'-'9') of length L > 2 (where L is even). One of

You are given a C++ string consisting of any lowercase alphanumeric characters ('a'-'z', '0'-'9') of length L > 2 (where L is even). One of the characters occurs L/2 number of times. The other characters are all different. For this problem, do not use any existing find or search string functions. Write a function that find this one character that occurs L/2 number of times in the input string:

char findHalfDuplicate(string s);

For example:

"1a2a3a4a"; // L = 8; 'a' occurs 4 times; the other characters are all different "a2a3a1"; // L = 6; 'a' occurs 3 times; the other characters are all different "2aa3"; // L = 4; 'a' occurs 2 times; the other characters are all different

Not valid input:

"1a"; // L has to be > 2 "z"; // L has to be even

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

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

1.1 What are the main functions of financial managers?

Answered: 1 week ago

Question

=+How should we organize a book to maximize learning and interest

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago

Question

4. Did you rethink your decision?

Answered: 1 week ago

Question

3. Did you seek anyones advice?

Answered: 1 week ago