Member-only story

Interview question: Determine the smallest and largest element of an unsorted array

Crystal X
2 min readMay 30, 2023

--

It is very important to know how to code basic algorithms at a coding interview, because a potential python developer does not know exactly what questions are going to be asked. One common interview question that can be asked to to determine the largest and smallest elements of an unsorted array.

In this blog post I will demonstrate two ways that this interview question can be answered, and it is up to the interviewee to determine the best way to answer the question.

The first solution to this question is to implement a for loop, and the psuedocode for for this algorithm is cited below:-

  1. Define a list of unsorted numbers, lst_1.
  2. Define a function, find_min_max, which will accept the list as its input.
  3. Within the function, define the variables, min_num and max_num, which are both set to 0.
  4. Within the function, create a for loop that will iterate from 0 to the unsorted list with an increment of 1. If the incremented element is less than min_num then min_num becomes that number. If the incremented element is larger than max_num then max_num becomes that number.
  5. When the for loop has completed its iterations, the function is finished and return the…

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet