Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

We can use this regex to check the above conditions: ^[a-zA-Z0-9_]+@[a-zA-Z0-9]+\\.edu$

In this regex, we check for the start to be one of more instance of [a-zA-Z0-9_]. There can be more valid characters here. i'm just including these.
This must be followed by an '@' sign which must be followed by some characters of pattern [a-zA-Z0-9] then a '.' and finally ends with an 'edu' text.

A sample java program is:

public class emailValidator {

	public static void main(String[] args) {
		String input = "xyz@alumni.univ.edu";

		try {
			if (input.matches("^[a-zA-Z0-9_]+@[a-zA-Z0-9]+\\.edu$") == true)
				System.out.println("valid email");
			else
				System.out.println("invalid email");
		}

		catch (Exception e) {
			e.printStackTrace();
		}

	}

}

- Jester January 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think the correct regex should be
^[a-zA-Z0-9_\\.]+@[a-zA-Z0-9\\.]+\\.edu$
Since there can be a '.' after or before the @sign as well.

- doomguy January 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Ideally e-mail cannot start with a dot (.) . The reg x as per the question constraints should be ^[_A-Za-z0-9-]+@[_A-Za-z0-9]+(\\.edu)$

- Anonymous January 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Actually I mean it should be as below ...
"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[_A-Za-z0-9]+(\\.edu)$";

- Girish January 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Agreed with devdeep. We should specify that the intended algorithm is to match the input string to the regex and accept the string iff the match of the regex is exactly the whole input string. Furthermore, the regex should be told to match the maximum pattern that corresponds to the regex. That is, helloworld@stuff.educational.edu shouldn't match helloworld@stuff.edu and thus fail the test specified above.

- eugene.yarovoi January 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Regex for any email id, that can ends with com edu or anything:
^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+
(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$

^ #start of the line
[_A-Za-z0-9-]+ # must start with string in the bracket [ ], must contains one or more (+)
( # start of group #1
\\.[_A-Za-z0-9-]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #1, this group is optional (*)
@ # must contains a "@" symbol
[A-Za-z0-9]+ # follow by string in the bracket [ ], must contains one or more (+)
( # start of group #2 - first level TLD checking
\\.[A-Za-z0-9]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #2, this group is optional (*)
( # start of group #3 - second level TLD checking
\\.[A-Za-z]{2,} # follow by a dot "." and string in the bracket [ ], with minimum length of 2
) # end of group #3
$ #end of the line

- CareerCupUser1 January 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have a solution proposal which needs some attention. I am thinking of having a method for checking the valid email address which takes string as an input.
public boolean emailChecker(String s) {
boolean flag = false;
String input = s.split("@"); //split the email address from the @ onwards
//Now if input does NOT startWith("alumni") and contains("edu") then we can set the flag as true;
if(!(input.startsWith("alumni") && input.contains("edu")) { flag = true; }
return flag;
-------
The above code needs clarification. I mean is this correct or am I missing out on any information.
Thanks!!

- renegade January 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@renegade
Your solution is correct but not complete. You are focusing on only the sample input string given in the question.
In case you want to filter out many other substrings like "alumni" etc, your code size will keep on increasing and it will be difficult to maintain that code.

- Learner January 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@learner
at this point of time it is said that you have only one special case...

- p February 19, 2012 | Flag


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