Member-only story

Interview question: Get matching elements of an integer array

Crystal X
2 min readMay 24, 2023

--

A person who is going to go on a coding interview is going to no doubt be asked coding questions, for which he is going to have to solve at the interview. The interview question discussed in this blog post is how to get matching elements of an integer array.

The psuedocode to accomplish this task is:-

  1. Define a list, lst, which has matching elements in it.
  2. Define a function, find_match, which will accept the list as its input.
  3. Within the function, define an empty array, match_element.
  4. Within the function, define a for loop that iterates through 0 to the length of the list at an increment of 1. The iterator is the variable, i.
  5. Within the for loop, define a second for loop that will iterate from the variable I+1 to the length of list at an increment of 1. The iterator is the variable 1. Within this loop, if the element in position i is the same as the element in the position of j, append the array, match_element, with the element in position i.
  6. When the two loops have completed their iterations, the function will return the array, match_element, which contains the matching elements.

The code in Python for this algorithm can be seen below:-

--

--

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