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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manas MohapatraRank #182 · 13.2K reputationPosted Aug 7, 2015, 10:32 AM EDT
Ramesh MaruthiRank #937 · 2.2K reputationPosted Aug 7, 2015, 10:37 AM EDT
{
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;
}
}