Vistaprint

  www.vistaprint.com
  www.vistaprint.com

Interview Question

Software Engineer Interview(Student Candidate) Lexington, MA

Choose a data structure to store the extracted words and

  their positions in a sentence and then bring the sentence back using any language you like. Writing code on paper.
Tags:
hashmap
Answer

Interview Answer

2 Answers

0

HashMap

Interview Candidate on Nov 3, 2011
0

Keep it in a dictionary (python) or a hashmap (java) <Word , <list of position>>

TO bring sentence back
1) find the max location in the dictionary.
 Size of entire string = location + size of the word
2) Create new char array new_blank_array[Size of entire string]
3) traverse the dictionary and place the words as per their respective place.

Complexity : O(n)

Jayanth on Oct 22, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.