title: Algorithm to build JSON Object
body: <p>Inputs are given in below format:-</p>
  
  <p><strong>CHAR->CHAR->CHAR->......any number times = INTEGER</strong></p>
  
  <p>Here, CHAR - any character which represents Key.
        INTEGER - any integer value which represents value of this relation.</p>
  
  <p>There are number of such sequences given to us. We have to produce JSON format for that.</p>
  
  <p>Example :-</p>
  
  <pre><code>a-&gt;b = 12
  a-&gt;b = 20
  a-&gt;c-&gt;d = 190
  a-&gt;d = 300
  a-&gt;c-&gt;e = 90
  c = 18
  </code></pre>
  
  <p>Output :-</p>
  
  <pre><code>{
    a : {
         b :[12, 20],
         c : {
              d : [190]
              e : [90]
         }
         d : [300]
    }
    c : [18]
  }
  </code></pre>
  
  <p><strong>Wrong Case</strong></p>
  
  <p>If any key has value and it going to point to any other key, then it should not possible</p>
  
  <p>Example :-</p>
  
  <pre><code>a : {
       [15],
       d : {
            // something here
       }
  } 
  </code></pre>
  
  <p><strong>My algorithm</strong> :-</p>
  
  <ol>
  <li>I used Linked List data structure for building this pattern.</li>
  <li>Use two arrays, Nodes, and Forest, every index represents one character, means 0 represents a, .... 25 represents z.</li>
  <li>Nodes contains all the linking from one key to other, an if it end, then it contains array of integer that  shows values.</li>
  <li>Forest represents all the roots of different trees, for above case, <code>a</code> and <code>c</code> are roots for two trees.</li>
  <li>Perform all the linkings and update Nodes, and Forest both array.</li>
  <li>Finally at the end, iterate through Forest array and if it true create a tree using this as a root.</li>
  </ol>
  
  <p>This is my algorithm, but it is not correct. Please help me in correcting my algorithm or developing new one.</p>