Computer Science, asked by mvsrilalith2019, 2 months ago

How many minimum string traversals are required to find first non-repeating character in a string?​

Answers

Answered by chanannadiwal35
0

Answer:

Find the first non-repeating character in a string by doing only one traversal of it. Given a string, find the first non-repeating character in it by doing only a single traversal of it. A simple solution would be to store each character's count in a map or an array by traversing it once.

Answered by vishakasaxenasl
0

Answer:

Minimum one-string traversals are required to find the first non-repeating character in a string.

Explanation:

The number of traversals depends on your approach to writing the logic for finding the first non-repeating character in the string.

However, a minimum of one string traversal is sufficient for performing the mentioned task.

You can use one of the following approaches for doing this:

Approach 1:

  • Start iterating over the stirng.
  • Store each repeated character in a new string or list.
  • As soon as you find the non-repeating character your search is complete.

Approach 2:

  • Use a hash table
  • Store each character of the string as the key of the hash table.
  • Store the number of occurrences of the character as their values.
  • The key which has the first one value is your first non-repeating character.

#SPJ2

Similar questions