Adobe Interview Question


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

^[atrw].*|^sl|boom|^ch

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:

import java.util.regex.*;  
  public class JavaFiddle
  {
    public static void main(String[] args)
    {
      String[] arr = {"ache", "slow", "torn", "slum", "boom", "rival", "wrong", "cholera", "revenge", "arrogant", "papa", "book", "home", "cars", "jolly", "sugar", "friend", "mother", "father", "bloomiest"};
      for(int i =0; i < arr.length; i++) {
          System.out.println(arr[i] + ": " + test(arr[i]));
      }
      
    }
    
    public static String test(String str) {
        Pattern p = Pattern.compile("^[atrw].*|^sl|boom|^ch");
        Matcher m = p.matcher(str);
        return m.find() ? "Bad" : "Good";
    }
  }

output:
> 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

- Will June 03, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Anonymous June 04, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More