C# Solution for Uncommon Words from Two Sentences Problem
Intuition\n Describe your first thoughts on how to solve this problem. \nIn this approach, instead of using a HashMap for counting word frequencies, we will use
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn this approach, instead of using a HashMap for counting word frequencies, we will use a concatenated sentence and grouping to identify uncommon words.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.\tConcatenate Sentences:\nInstead of handling two sentences separately, we concatenate them into one sentence by adding a space between them. This allows us to treat them as a single string.\n2.\tSplit Words:\nWe split the concatenated string into individual words using the Split() function.\n3.\tGroup Words and Count Occurrences:\nUsing LINQ, we group the words and count how many times each word appears. We use the GroupBy() function, which groups words by their value, and then we filter out words that appear more than once using Where(g => g.Count() == 1).\n4.\tReturn the Result:\nThe words that appear exactly once are selected and converted into an array to return the result.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\u2022\tConcatenating the Sentences:\nConcatenating s1 and s2 takes O(n + m), where n is the length of s1 and m is the length of s2.\n\u2022\tSplitting the Words:\nSplitting the concatenated sentence into words takes O(n + m).\n\u2022\tGrouping and Counting:\nGrouping the words and counting their occurrences takes O(p), where p is the number of unique words. This includes filtering the uncommon words.\n\nThus, the overall time complexity is: O(n + m + p) \n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\u2022\tStorage for Words:\nWe need space to store the words from the combined sentence, which would require O(n + m).\n\u2022\tGrouping and Counting Storage:\nThe grouping step creates groups for each unique word, requiring O(p) space, where p is the number of unique words.\n\nThus, the space complexity is: O(n + m + p) \n\n# Code\n```csharp []\npublic class Solution {\n    public string[] UncommonFromSentences(string s1, string s2) {\n        // Concatenate both sentences with a space in between\n        string combined = s1 + " " + s2;\n\n        // Split the combined sentence into words\n        string[] words = combined.Split(\' \');\n\n        // Group the words and count their occurrences using LINQ\n        var wordGroups = words.GroupBy(w => w)\n                              .Where(g => g.Count() == 1) // Only select words that appear exactly once\n                              .Select(g => g.Key);        // Select the word itself\n\n        // Convert the result to an array and return\n        return wordGroups.ToArray();\n    }\n}\n```
['C#']