NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

You are given a string s consisting of alphabetic characters ('A'-'Z', 'a'-'z). Build a binary tree that represents the frequency distribution of characters in s under the following conditions:

  1. Leaf Nodes:
    • Each distinct character in s must appear exactly once as a leaf node.
    • A leaf node contains:
      • ch: the character itself.
      • count: the number of times that character appears in s.
  2. Internal Nodes:
    • Every internal node must have:
      • ch set to '#'.
      • count equal to the sum of the count values of all leaves in its subtree.
Stdout
-