iLabs Interview Question for Senior Software Development Engineers


Country: India
Interview Type: Phone Interview




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

1. Sort the characters in each word in the dictionary and use that as key to add in HashMap with value as linked list in which we need to add words as they are.
2. Sort the characters in 'given word' and using that as key retrieve the linked list from above HashMap.
3. Print the contents of above linked list.

- arunbabuasp July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

For each word in the dictionary that has the same length as the input string, sort the characters in the word and see if it's the same as the input string when sorted.

static LinkedList<String> findAnagrams(String s, HashSet<String> dict) {
  s = sort(s);
  LinkedList<String> anagrams = new LinkedList<String>();
  for(String word : dict) {
    if(word.length() == s.length() && sort(word).equals(s)) {
      anagrams.add(word);
    }
  }
  return anagrams;
}

static String sort(String s) {
  char[] arr = s.toCharArray();
  Arrays.sort(arr);
  return new String(arr);
}

- Sunny July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Generate all the anagrams of the word and then look up into the dictionary for each anagram.
For the matches found in the dictionary return the list.

- subahjit July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@subahjit
I suppose, you meant to generate all the permutations of the given input word, but not the "anagrams".

- ashot madatyan July 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ashot
Yes all the permutations of the characters of the given word taking all the characters in a single permutation.
Then the dictionary look up.
I have assumed that the dictionary look up apis are given and we do not have to design the dictionary data structure.

- subahjit July 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

<script>
</script>

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

i think we can use of trie data structure..if u dont bother for more space complexity

- shikhil July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printAnagrams(node  root
)

- Anonymous July 07, 2013 | 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