Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started