Google Interview Question for Software Engineers


Country: United States




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

I feel this question can be solved by stack. once we found previous element in the stack is larger than current element, than pop out

- lixx3527 July 09, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ss

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

def makeheap( heap, start, N ):
	for i in reversed( xrange( start, N/2 +1 ) ):
		heapify( heap, i, N )

def heapify( heap, i, last ):
	while(1):
		l = i*2
		r = i*2 +1
		if l >= last:
			return
		if r >= last:
			m = l
		else:
			if heap[l] <= heap[r]:
				m = l
			else:
				m = r
		if heap[m] < heap[i]:
			heap[m],heap[i] = heap[i],heap[m]
			i = m
		else:
			return

	
def lexi( arr, k):
	n = len(arr )
	heap = [ i for i in arr]
	makeheap( heap, 0, len(arr))
	h = dict()
	for ind,i in enumerate(arr):
		if i in h:
			h[i].append( ind )
		else:
			h[i] = [ind]
	
	i =0
	start = 0
	end = n - k
	res = ""
	last = n-1
	c = 0
	print h
	while c < k:
		print heap
		index = h[ heap[0] ][0] 
		print index
		if index > start and index < n - k+ c:
			res+= heap[0]
			c+=1
			start = index
			del h[heap[0]][0]
		heap[0] = heap[last]
		last-=1
		heapify( heap, 0, last )
	return res

print lexi( ["5","1","2","4","12","2"],2)

- Newman October 07, 2019 | 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