Find longest word without repeating characters in given sentence.
E.g. Sanatana dharma is the oldest dharma in the world.
Output :- oldest
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ramesh MaruthiPosted Aug 7, 2015, 2:37 PM
{
static void Main(string[] args)
{
string s = "Sanatana dharma is the oldest dharma in the world";
Program p = new Program();
string noduplicateandlongest= p.findLongestWord(s);
Console.WriteLine("The longest word without duplicate value is {0}", noduplicateandlongest);
Console.ReadLine();
}
public string findLongestWord(string big)
{
string[] split = big.Split(new[] { ' '}, StringSplitOptions.RemoveEmptyEntries );
var lis = split.ToList();
List
foreach(string s in lis)
{
char[] charr = s.ToCharArray();
bool val = charr.Distinct().Count() == charr.Length;
if (val)
{
nodups.Add(s);
}
}
var result = nodups.OrderByDescending(s => s.Length).FirstOrDefault();
return result;
}
}
Manas MohapatraPosted Aug 7, 2015, 2:32 PM