Adobe Interview Question
Country: India
Interview Type: Written Test
string pattern = @"\w*(pa|k|me|s|y|r|d|st)$";
string[] goodWords = new string[] { "papa", "book" , "home", "cars" , "jolly" ,
sugar", "friend", "mother", "father", "bloomiest", };
foreach (var word in goodWords)
{
Trace.WriteLine(Regex.Match(word,pattern).Success ? $"{word} : good": $"{word} : bad");
}
string[] badWords = new string[] { "ache", "slow", "torn", "slum", "boom", "rival", "wrong", "cholera", "revenge", "arrogant", };
foreach (var word in badWords)
{
Trace.WriteLine(Regex.Match(word, pattern).Success ? $"{word} : good" : $"{word} : bad");
}
Output:
papa : good
book : good
home : good
cars : good
jolly : good
sugar : good
friend : good
mother : good
father : good
bloomiest : good
ache : bad
slow : bad
torn : bad
slum : bad
boom : bad
rival : bad
wrong : bad
cholera : bad
revenge : bad
arrogant : bad
Matches only against the second set. No words in the first set start with a, t, r, or w. And words starting with s, b, or c are distinguished from the first set by additional characters.
Code: not really a java programmer, but this works in java fiddle:
output:
- Will June 03, 2018> Running...
ache: Bad
slow: Bad
torn: Bad
slum: Bad
boom: Bad
rival: Bad
wrong: Bad
cholera: Bad
revenge: Bad
arrogant: Bad
papa: Good
book: Good
home: Good
cars: Good
jolly: Good
sugar: Good
friend: Good
mother: Good
father: Good
bloomiest: Good