Apple Interview Question for Staff Engineers


Country: United States




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

Never re-invent the wheel. You are in Darwin, and you should simply use:

[ stackoverflow.com/questions/6637882/how-can-i-use-grep-to-show-just-filenames-no-in-line-matches-on-linux/6637894 ]
And yes, you can simply use grep.
[ digitalocean.com/community/tutorials/using-grep-regular-expressions-to-search-for-text-patterns-in-linux ]

Thus, the solution is really using regex in grep with "-l" option.

- NoOne March 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A simple regex of the form \(?\d{3}\)?-(\d{3})-(\d{4}) will do for this problem. The idea is to compile or apply the regex to the text contained in various files from the directory. I present a simple solution in Python using regex below. I have used the verbose option to explain each symbol in my regex for clarity:

My solution:

import re
def findPhoneNumbers(text):
  phoneNumberPattern = re.compile(r'''
    \(?     # The particular regex might optionally start with a (
    (\d{3})   # Followed by the area code
    \)?     # Followed optionally by a parenthesis
    -       # Followed by a hyphen
    (\d{3}) # Followed by three digits 
    -       # And a hyphe
    (\d{4}) # And last 4 digits
    ''', re.VERBOSE)
  return phoneNumberPattern.findall(text)

Test code:

text = r'''
<p><b>This is a text string. Phone number is (111)-111-1111.
</b>This is a second phone number which follows a different format of 222-222-2222.</p>
<b>But if I have a phone number which is of the format 333.333.3333, then my regex shouldn't find it.
'''
print(findPhoneNumbers(text))

Output:

[('111', '111', '1111'), ('222', '222', '2222')]

- prudent_programmer March 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String []args){
String date = "\\([1-9]{1}[0-9]{2}\\)-[0-9]{3}-[0-9]{4}";
System.out.println("(902)-934-9945".matches(date));
}

- Anonymous May 18, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String []args){
String date = "\\([1-9]{1}[0-9]{2}\\)-[0-9]{3}-[0-9]{4}";
System.out.println("(902)-934-9945".matches(date));
}

- kkk May 18, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String []args){
        String date = "\\([1-9]{1}[0-9]{2}\\)-[0-9]{3}-[0-9]{4}";
        System.out.println("(902)-934-9945".matches(date));
     }

- kkk May 18, 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