Pinterest Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

-EDIT-

This won't work. Will try another approach.

- Cerberuz February 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think they did't give you a fixed word. instead you are just given a list of words and you need to consider every possibility

- zyfo2 February 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is similar to the box problem, which asks for putting bigger box under smaller boxes and returning the max height from a list of boxes

use one integer as bit vector to represent the current word
pseudo code:
int maxlength(int bitvector){
max=0;
for(word: list){
if(word contains the previous bit vector){
update the bit vector
if(maxlength(bitvector)>max) update max;}
}
besides use memorizing to reduce duplicates

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

Try building a suffix tree and find the longest common branch

- Max November 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Suffix Tree/trie wouldn't work here since the strings are permutation of each others with some additional words.

- Aditya November 14, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]

def hash_anagram(s):
    hash = 1
    for c in s.lower():
        hash *= primes[ord(c) - ord('a')]
    return hash


def longest_anagram_derivative(words):
    hashedWords = [(hash_anagram(w), w) for w in words]
    hashedWords.sort(reverse=True)
    for i, (hashCode, word) in enumerate(hashedWords):
        for j in range(i + 1, len(hashedWords)):
            if hashCode % hashedWords[j][0] == 0:
                return word
    return None


print longest_anagram_derivative(['a', 'cat', 'tack', 'tacky', 'bla', 'able', 'whatever']) # prints: whatever
print longest_anagram_derivative(['b', 'cat', 'tack', 'tacky', 'bla', 'able', 'whatever']) # prints: tacky

- elgeish April 04, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]

def hash_anagram(s):
    hash = 1
    for c in s.lower():
        hash *= primes[ord(c) - ord('a')]
    return hash


def longest_anagram_derivative(words):
    hashedWords = [(hash_anagram(w), w) for w in words]
    hashedWords.sort(reverse=True)
    for i, (hashCode, word) in enumerate(hashedWords):
        for j in range(i + 1, len(hashedWords)):
            if hashCode % hashedWords[j][0] == 0:
                return word
    return None


print longest_anagram_derivative(['a', 'cat', 'tack', 'tacky', 'bla', 'able', 'whatever']) # prints: whatever
print longest_anagram_derivative(['b', 'cat', 'tack', 'tacky', 'bla', 'able', 'whatever']) # prints: tacky

- elgeish April 04, 2016 | 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