Hacker Rank: Counting names with prefix matches using a trie Practicing hacker rank questions and would love some feedback on how I could perform optimizations on a Trie.
This code will add a bunch of names into a trie and then when asked will turn how many names belong to a partial match. eg.

jenn, jennifer, george, jenny

partial =&gt; jen
return =&gt; 3


using System;
using System.Collections.Generic;
using System.IO;

namespace ConsoleApplication1
{
    class Solution
    {
        static void Main(String[] args)
        {
            int N = Int32.Parse(Console.ReadLine());
            string[,] argList = new string[N, 2];
            for (int i = 0; i &lt; N; i++)
            {
                string[] s = Console.ReadLine().Split();
                argList[i, 0] = s[0];
                argList[i, 1] = s[1];
            }

            Trie trie = new Trie();

            for (int i = 0; i &lt; N; i++)
            {
                switch (argList[i, 0])
                {
                    case &quot;add&quot;:
                        trie.add(argList[i, 1]);
                        break;
                    case &quot;find&quot;:
                        Console.WriteLine(trie.find(argList[i, 1]));
                        break;
                    default:
                        break;
                }
            }
        }
    }

    class Trie
    {
        private readonly Trie[] _trieArray = new Trie[26];
        private int _findCount = 0;
        private bool _data = false;
        private char _name;
        private int _occurances = 0;

        public void add(string s)
        {
            s = s.ToLower();
            add(s, this);
        }

        private void add(string s, Trie t)
        {
            char first = Char.Parse(s[0].ToString());
            int index = first - 'a';

            if (t._trieArray[index] == null)
            {
                t._trieArray[index] = new Trie {_name = first};
            }

            if (s.Length &gt; 1)
            {
                add(s.Substring(1), t._trieArray[index]);
            }
            else
            {
                t._trieArray[index]._data = true;
            }
        
            t._trieArray[index]._occurances++;
        }

        public int find(string s)
        {
            s = s.ToLower();
            find(s, this);

            int ans = _findCount;
            _findCount = 0;
            return ans;
        }

        private void find(string s, Trie t)
        {
            if (t == null)
            {
                return;
            }
            if (s.Length &gt; 0)
            {
                char first = Char.Parse(s[0].ToString());
                int index = first - 'a';
                find(s.Substring(1), t._trieArray[index]);
            }
            else
            {
                _findCount = t._occurances;
            }
        }

    }
}
You don't validate your input.  If the user enters a string with no space in it, you'll get an exception.

s[0] is a character, so why do you convert it to a string to convert it back to a character?

You should avoid allocating _trieArray until you need it.  Otherwise you'll allocate a bunch of memory you don't use (in all your leaf nodes).

You don't need to use _findCount.  Your private find method can just return that value.

As an additional exercise, rewrite add to not be recursive, and avoid making all those (sub)string copies.