Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions CodingChallenge.FamilyTree/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,32 @@ public class Solution
{
public string GetBirthMonth(Person person, string descendantName)
{
throw new NotImplementedException();
// check if the person argument is null
if (person == null)
{
return null;
}

// check if the current person is the one we're looking for
if (person.Name == descendantName)
{
return person.Birthday.ToString("MMMM");
}

// if not, recursively search through this person's descendants
foreach (Person descendant in person.Descendants)
{
string birthMonth = GetBirthMonth(descendant, descendantName);

// if a non-empty string is returned, we've found the person
if (!string.IsNullOrEmpty(birthMonth))
{
return birthMonth;
}
}

// person was not found in the family tree
return null;
}
}
}
}
18 changes: 13 additions & 5 deletions CodingChallenge.PirateSpeak/Solution.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace CodingChallenge.PirateSpeak
{
public class Solution
{
public string[] GetPossibleWords(string jumble, string[] dictionary)
{
throw new NotImplementedException();
public string GetPossibleWords(string scrambled, string[] dictionary)
{
// sort the scrambled word letters
var sortedScrambled = String.Concat(scrambled.OrderBy(c => c));

// use LINQ to find all words in the dictionary that, when sorted, match the sorted scrambled word
var matches = dictionary.Where(word => String.Concat(word.OrderBy(c => c)) == sortedScrambled);

// return the joined matching words into a single string, separated by a comma and a space
return string.Join(", ", matches);
}
}
}
}
}