| Q & A Home |
| Math |
| Science |
| History |
| IT & Web |
| Programming |
| Health |
| Business |
| Arts & Humanities |
| Social Studies |
| Engineering & Technology |
| Arts & Entertainment |
| Humanities |
| Sports |
| Auto |
| Hobbies |
| Books and Literature |
| Electronics |
| Food & Drink |
| Jobs & Education |
| Law & Government |
| Travel & Places |
| People & Society |
| Beauty & Health |
| Animals & Plants |
| Other |
Oaliur Rahman 29 Jun, 2024 11:48:17 PM 1 152
Best Answer: A character is non-repeating if its frequency in the string is a unit. To find such characters, find the frequency of all characters in the string and check which character has a unit frequency. This can be done using a hash_map, which will map each character to its respective frequency. You can simultaneously update the frequency of any character you come across in constant time (note that hash_map can only handle up to 256 characters at a time). Read the string again and the first character which has a frequency as a unit is the answer.
Algorithm:
Make a hash_map that will map the character to their respective frequencies.
Traverse the given string using a pointer.
Increase the count of the current characters in the hash_map.
Now traverse the string again and check whether the current character hasfrequency=1.
If the frequency >1, continue the traversal.
Else break the loop and print the current character as the answer.
Oaliur Rahman 29 Jun, 2024 11:48:17 PM