Hi5 Interview Question for Accountants






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

A working 3-line python code for QuickSort.

def qsort(L):
    if len(L) <= 1: return L
    return qsort( [ lt for lt in L[1:] if lt < L[0] ] )  +  \ 
              [ L[0] ]  +  qsort( [ ge for ge in L[1:] if ge >= L[0] ] )

Now this is the power of Python. Expressiveness!!!

A Bigger version

def qsort1(lst):
	if len(lst) <= 1:
		return lst
	pivot = lst.pop(0)
	greater_eq = qsort1([i for i in lst if i >= pivot])
	lesser = qsort1([i for i in lst if i < pivot])
	return lesser + [pivot] + greater_eq

- LLOLer August 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@LLOLer
I like the first solution. Very smartly done. Quicksort in just 3 lines!, in fact it is just 2 lines baring the def stmt. Thank you for this nice solution.

- lickie August 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* quicksort */
def _partition_( arr, l, r ){
  v = arr[r]
  i = l
  j = r - 1 
  while ( true ){
    while ( arr[i] < v ){ i += 1 }
    while ( arr[j] > v ){ j -= 1 }
    break( i >= j )
    t = arr[i] ; arr[i] = arr[j]; arr[j] = t 
  } 
  t = arr[i] ; arr[i] = arr[r]; arr[r] = t
  i // return  
}

def _qs_(arr, l, r ){
  if ( l >= r ) return  
  // now here
  i = _partition_(arr,l,r)
  _qs_(arr,l,i-1)
  _qs_(arr,i+1,r)
}

def quicksort( arr ){
   _qs_(arr, 0, size(arr) - 1)
}

l = list( [0:13] ) as  { random(100) }
println( l )
quicksort(l)
println(l)

- NoOne April 19, 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