## Bank of America Interview Question for Dev Leads

Country: United States

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

Store all the words in Trie data structure. Trie structure is

``````class Trie{
HashMap<Character,Trie> book;
int pageNum;
Trie(int pageNum){
book=new HashMap<>();
this.pageNum=pageNum;
}``````

}
or store each page in a trie. start from the page 1 and insert words into trie, if a repeated word exists we already have the page number of the same word which occurred first. Time complexit is (w1.length+w2.length)

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

@sivapraneethalli This is a good idea when the Book is a constant and the words are variable. My question is that for every request, we get a new book and two new words. For such a case, the space and time of storing the complete book in Trie would be large and also unnecessary task.

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

This problem seems simplified version of finding minimum distance between those 2 words. Here since we need to find distance between first occurrences, just start from start of book and maintain idx = -1. If we encounter any of word, store it's index and look for next word.

``````// convert book into list of words
int idx = -1;
for (int i  = 0; i < list.size(); i++) {
if (list[i] == w1 || list[i] == w2) {
if (idx != -1) {
if (list[i] != list[idx])
return i - idx;
}
else
idx = i;
}
}
return -1; // no pair found``````

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.

### 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.