<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thangaraj N</title>
    <description>The latest articles on DEV Community by Thangaraj N (@thangarajn1992).</description>
    <link>https://dev.to/thangarajn1992</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F617753%2F5d71c056-3346-48ad-bfc5-dd668992bc9d.jpg</url>
      <title>DEV Community: Thangaraj N</title>
      <link>https://dev.to/thangarajn1992</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thangarajn1992"/>
    <language>en</language>
    <item>
      <title>Leetcode Solutions Index </title>
      <dc:creator>Thangaraj N</dc:creator>
      <pubDate>Tue, 20 Apr 2021 09:55:14 +0000</pubDate>
      <link>https://dev.to/thangarajn1992/leetcode-solutions-index-2ad6</link>
      <guid>https://dev.to/thangarajn1992/leetcode-solutions-index-2ad6</guid>
      <description>&lt;p&gt;As I started to solve leetcode problems, wanted to document those somewhere where it might be useful for others as well. And so here you are at the main index page of my Leetcode solutions and explanations. I have organized the solutions based on their difficulty level and added a column to show which topics they can be related to. I hope these solutions will be useful for each one of you, if so, please like the posts which helped you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hard-Level Problems
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Problem Title&lt;/th&gt;
&lt;th&gt;Related Topics&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Medium-Level Problems
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Problem Title&lt;/th&gt;
&lt;th&gt;Related Topics&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Easy-Level Problems
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Problem Title&lt;/th&gt;
&lt;th&gt;Related Topics&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;589&lt;/td&gt;
&lt;td&gt;&lt;a href="https://dev.to/thangarajn1992/c-solution-n-ary-tree-preorder-traversal-45i5"&gt;N-ary Tree Preorder Traversal&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Tree, DFS, Preorder&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>algorithms</category>
      <category>programming</category>
      <category>cpp</category>
    </item>
    <item>
      <title>Cpp Solution: N-ary Tree Preorder Traversal (leetcode 589)</title>
      <dc:creator>Thangaraj N</dc:creator>
      <pubDate>Tue, 20 Apr 2021 09:54:07 +0000</pubDate>
      <link>https://dev.to/thangarajn1992/c-solution-n-ary-tree-preorder-traversal-45i5</link>
      <guid>https://dev.to/thangarajn1992/c-solution-n-ary-tree-preorder-traversal-45i5</guid>
      <description>&lt;p&gt;This is part of a series of Leetcode solution explanations (&lt;a href="https://dev.to/thangarajn1992/leetcode-solutions-index-2ad6"&gt;index&lt;/a&gt;). If you liked this solution or found it useful, please like this post and/or upvote my solution post on Leetcode's forums.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/n-ary-tree-preorder-traversal/"&gt;LeetCode Problem #589 Link&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem:
&lt;/h3&gt;

&lt;p&gt;Given the root of an n-ary tree, return the preorder traversal of its nodes' values.&lt;/p&gt;

&lt;p&gt;N ary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Example 1&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Input&lt;/td&gt;
&lt;td&gt;root = [1,null,3,2,4,null,5,6]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Output&lt;/td&gt;
&lt;td&gt;[1,3,5,6,2,4]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Visual&lt;/td&gt;
&lt;td&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8v2_KXn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/thangarajn1992/leetcode/main/Challenges/500_600/589_N_ary_Preorder_Tree_Traversal/589_Example1.png" alt="alt text" title="Example1"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Example 2&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Input&lt;/td&gt;
&lt;td&gt;root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Output&lt;/td&gt;
&lt;td&gt;[1,2,3,6,7,11,14,4,8,12,5,9,13,10]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Visual&lt;/td&gt;
&lt;td&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lRLM4MnX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/thangarajn1992/leetcode/main/Challenges/500_600/589_N_ary_Preorder_Tree_Traversal/589_Example2.png" alt="alt text" title="Example2"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h6&gt;
  
  
  Constraints:
&lt;/h6&gt;

&lt;blockquote&gt;
&lt;p&gt;The number of nodes in the tree is in the range &lt;strong&gt;[0, 10^4]&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;0 &amp;lt;= Node.val &amp;lt;= 10^4&lt;/strong&gt;&lt;br&gt;
The height of the n-ary tree is less than or equal to &lt;strong&gt;1000&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Idea/Approach:
&lt;/h3&gt;

&lt;p&gt;Pre-order traversal is one type of Depth-First Search (DFS) algorithm. We can solve this problem by using the recursive DFS option. ( add the root(parent) to the result and call DFS recursively for each child)&lt;/p&gt;

&lt;h3&gt;
  
  
  C++ Solution:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public:
    vector&amp;lt;int&amp;gt; result;
    void preorderutil(Node * root) {
        result.push_back(root-&amp;gt;val);
        int size = root-&amp;gt;children.size();
        for(int i = 0; i&amp;lt; size; i++)
            preorderutil(root-&amp;gt;children[i]);
    }
    vector&amp;lt;int&amp;gt; preorder(Node* root) {  
        if(!root)
            return {};
        preorderutil(root);
        return result;

    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>algorithms</category>
      <category>cpp</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
