Interview Question


Country: United States
Interview Type: Written Test




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

I suspect they are looking for grep! :-)

- mag December 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yup..probably a grep/find followed by uniq

- anonymouse December 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

simple

grep -p . '[0-9]{3}-[0-9]{3}-[0-9]{4} | [0-9]{10} | [0-9]{5}-[0-9][5]' > file

cat file | grep "-" | tr "-" "" > file1

cat file1 | sort | uniq

-------------

This will work ... it was asked in Amazon :)

-Yadu Mathur

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

as any algorithm can not avoid to read through the file, I think the only item we can improve is the operation we do to record the repeat things.

we can use the bit the record the repeat history.

take a simpler number for example: the number is 1-10.

so we can using memery block 0000 0000 00 to record the repeat history,
if 1 is appear , then the first position of the block will be set to 1, so the history record block will be 0000 0000 01,

then anytime new number read in , check the block ,if the bit is 1, then it is repeated.

we can using another bit block to record the results...

- oday December 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We may want to use String-like hash function to calculate hash code of a number (omitting all dashes etc). In the first pass populate the map of hash code to a number of repeats. On the second pass find out the numbers matching unique hash codes. With low memory this can be done on multiple machines by creating a map on each machine which covers MAX_INTEGER%num_of_machines hashes only.

- Oleg December 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution-1: As described above, we can store the phone number in a hashmap that contains mapping as key=phoneNumber and value=boolean. Where boolean value represents whether we have exactly 1 (or) more than 1 occurrences of phone number.

-----

Solution-2: We can keep reading the phone numbers from the file and we can prepare a trie (or) prefix tree. For each phone number we can store its frequency in trie at the leaf level.

- Mario December 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

$sed 's/-//g' * | sort -u

- Praveen December 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sort the files and then apply uniq.

sort *.html|uniq

- VG December 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

grep -o -P "\d{10}|\d{5}-\d{5}|\d{3}-\d{3}-\d{4}" filename|sort|uniq

- manas ranjan basa January 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

cat *.html | egrep '\b[0123456789-]*?\b]' | sed '/s/-//g' | sort -n | uniq

- intro February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what does option -p do in grep command....googled it but cant find good answer

- hina May 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Maybe it's not best, but it is work - find each needed file and read it to string variables, then using regular expressions extract phone numbers and save to array. You need save in one of the formats(xxxxxxxxxx, xxxxx-xxxxx, xxx-xxx-xxxx). And if You choose xxxxxxxxxx, You need delete symbols "-". If You want I can write code using c#.net, send me examples only.

Better idea - all symbols(and 2 empty) that not number or "-" You replace with " "(empty)
then string[] strs = STRING_HTML.Split(" ");
then remove if(length != 10, 11, 12) and analyze.

- vitaly radionov December 06, 2012 | 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