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)

- sivapraneethalli November 08, 2016 | Flag Reply
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.

- iamaniceboy16 November 09, 2016 | Flag Reply
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

- vishalsahunitt November 15, 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