Directi Interview Question for SDE1s


Country: India
Interview Type: Phone Interview




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

I have think of a O(n+m) solution, it would satisfied the questions but it seems odd, like a hack to the question.

1) O(M) find the minimum number in array H[] -> "v_min"
2) O(N) iterate over array a[] replacing higher values than "v_min" with "v_min" the max value will be "v_min"

- Dito9 February 01, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Taking same example but with 2 value of s[] , e[] and h[].

a[] = [2,4,8,6,7]
s[] = [1,0]
e[] = [3,4]
h[] = [5,4]

o/p = [4,4,4,4,4] max = 4

for(int i=0;i<s.length;i++) {
	int start = s[i];
	int end = e[i];
	while(start < end) {
		if(a[start] > h[i]) {
			a[start] = h[i];
		}
		start++;
	}
}
findMax() // iterate array to find maximum in O(n)

Time complexity in worst case will be- O(k*n)
k is the length of s[] . and n is length of a[]

It Can also be solve by using time overlap with stack algorithm.

- azambhrgn February 01, 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