Character Count Comparison

Cosmocoder
1 min readMar 24, 2023
  • JavaScript — AlgoExpert

Let’s keep this short and simple

This is AlgoExpert’s #24 “Generate Document”.

Our function will be passed two arguments.

They’re both strings and the first one is called “characters” and represents a characters available to us.

The second one (“document”) represents a string that we’re attempting to construct.

Our task is to determine whether or not we have enough of each letter in our first argument to successfully create our second argument.

Thinking it through

Simple enough, right?

  1. First, I want a frequency count of all letters in both arguments
  2. Then I’ll simply compare these counts to determine whether or not I can build out the document.
  3. If I can, I’ll return true and if not — false.

Full Solution

As mentioned above, what I’ve done is generated a tally of character frequencies in each argument and then compared them.

And that’s it!

Short and simple.

--

--

Cosmocoder

Hi. I’m Nathan and I’m a full-stack software dev making my way through DS and Algo. Looking forward to sharing experiences along the way.