Hash

Generate an occurrence array for each character in a string.

  • Input
    • a string
  • Output
    • occurrence of each character in string in the form of an array

Example

  • Input
    • character("Hello")
  • Output
    • [1, 1, 2, 2, 1]

Implementation

The algorithm is related to the concept of hashing, which maps characters to an array index for counting.

  1. Use an array to store the count of each character

Reference: