Google Interview Question for Software Engineer in Tests


Country: United States
Interview Type: In-Person




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

Another way to solve this could be:
Create a hashmap for the given strings with key as
"FirstLetter Number LastLetter" for example a4t (addict)
and when a query comes we can simply look into this hash map

- Ashupriya August 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
4
of 4 vote

for each string do the following
1. find string length (L), if it is 30 then
2. check s[0] is M and s[L-1] is K if yes then
3. verify rest of 28 characters are matching

if 1,2,3 steps are true then given string is not unique and return
if any of 1,2,3 is false then go for next string

- algos August 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 3 vote

We can make a trie from the given set of strings, and then look for the given string,

- Ashupriya August 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even trie takes time proportional to length of word for searching then how can it be more efficient here ?

And we would have to spend resources in maintaining and creating trie.

- akki August 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Still think modified KMP will be faster. The only modification needed is just before each "textIndex" changing, check if the last letter where M28K finishes is 'K'.

- GKalchev August 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I was thinking if we can create a Hash function for all strings and then check if any of the hash key matches for M28K. This will have the cost of creating Hash of all strings.

Thoughts?

- Andy2000 August 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I was thinking if we can create a Hash function for all strings and then check if any of the hash key matches for M28K. This will have the cost of creating Hash of all strings.

Thoughts?

- Andy2000 August 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Very Simple solution since creating Hash will have space complexity.
Iterate the list and XOR each iterative string with the given string M28K. If they are not 0 then it means it is unique.

- Andy2000 August 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

An anagram or something similer of the string will also give zero. Which will not lead to an answer.

- Psycho August 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I dont believe so. Can you write counter example pls? Hey can you share your email ID if possible?

- Andy2000 August 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If the input string is K28M then XOR with pattern(M28K) will return 0.
XOR operation only cares for the characters and not their order, which is not what we want in this problem

- chandershivdasani September 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can have a trie constructed. An additional bookkeeping of the a[0].count.a[count] at the every leaf will give us the answer. In fact, we might even get the answer before finishing constructing the trie!

- random_coder October 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the best way is compare the string with all the strings. This will be fastest since at the first mismatch there is no need to match rest of the words in string & go for next string.

- avinash October 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{class M28KStringFinder:

    def __init__(self,text):
        self.text=text
        self.key_str_dict=dict()
        self.key_frq_dict=dict()
    def getInStr(self):
        return self.text

    def isKeyUniq(self,key):
        if self.key_frq_dict.has_key(key):
            if self.key_frq_dict.get(key)==1:
                print key + " is unique"
                print self.key_str_dict.get(key)
            else:
                print key + " was not found or not unique"
    
    def populateHash(self):
        for string in self.text:
            cur_key = string[0]+str(string.__len__())+string[string.__len__()-1]
            self.key_str_dict[cur_key]=string
            if self.key_frq_dict.has_key(cur_key):
                self.key_frq_dict[cur_key]+=1
            else:
                self.key_frq_dict[cur_key]=1
            
list1=['a2w3e4r5ts','p0o9i8u7y6t5rs','s23edf4frcf3l','s23edf4fssa3l']

m28KStringFinder = M28KStringFinder(list1)
m28KStringFinder.populateHash()
m28KStringFinder.isKeyUniq('p14s')

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

I'm think:

# turn the 28 chars in the middle of M28K into bits
bits_target
for s in LIST:
  if len(s) == 30 and s[0] == 'M' and s[29] = 'K':
    # turn the 28 chars in the middle into bits
    bits_current
    # do xor for bits_current and bits_target
    # if result is 0, they are identical, return False
    # otherwise, continue with the next s
# after the LIST is exhausted, return True

- Nan June 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

boolean checkForUniqueStrings(String str){
 boolean[] char_set = new boolean[128]; //if it is ASCII string.
 for(int i=1; i<str.length()-1; i++){
  int val = str.charAt(i);
  if (char_set[val]){
       return false;
 }
 return true;
   
 }
}

//Time complexity is O(n); space complexity O(1).

- sunny July 28, 2017 | 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