Goldman Sachs Interview Question for Software Engineer / Developers






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

String ipAdd = "123.123.123.123";
sysout(verifyIpAddress(ipAdd))


boolean verifyIpAddress(String ipAdd) {

String regExp = "[0-2][0-5][0-5]\\.[0-2][0-5][0-5]\\.[0-2][0-5][0-5]\\.[0-2][0-5][0-5]";

return ipAdd.matches(regExp);
}

- Bobby March 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String regExp = "[0-2][0-5][0-5]\\.[0-2][0-5][0-5]\\.[0-2][0-5][0-5]\\.[0-2][0-5][0-5]";

return ipAdd.matche(regExp);

- Anonymous March 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

small correction

String regExp = "[0-2]?[0-5]?[0-5]?\\.[0-2]?[0-5]?[0-5]?\\.[0-2]?[0-5]?[0-5]?\\.[0-2]?[0-5]?[0-5]?";

return ipAdd.matche(regExp);

- Anonymous March 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

<jwz>Now you have two problems.</jwz>

- Anonymous March 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

anonymous - what are the two problems

- biggied88 March 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It's a quote by jwz. The above regex matches various malformed IPs like

....

and fails to match valid IPs like

192.168.0.1

.

- Anonymous March 05, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

string pattern = @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"

- Anonymous March 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@"^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.
([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$"; this is a right answer.

- komal May 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the regex above will work for REAL IP addresses ( except for 0.*.*.*) but the question say that the IP is passed as String so 000.000.000.000 will not be matched.
by modifying the above regex you get this: ^([0-9]|0[0-9][0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|0[0-9][0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$ which should work for all IP formats (REAL and string ones).

By REAL I mean 000.000.000.000 -> 0.0.0.0

- Anonymous October 05, 2010 | 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