Рет қаралды 2,224
I’m going to show you two ways of solving a typical interview-style question where we need to compare two arrays. The first solution is more obvious and less efficient. The second solution introduces a great problem-solving tool - frequency counter objects - which greatly improves the efficiency of the function.
The problem:
“Write a function called “squared” which takes two arrays. The function should return true if every value in the array has its value squared in the second array. The frequency of values must be the same.”
At first, I will show you the “Naïve” way of solving the problem - the more obvious way that isn’t efficient. I’ll then show you an efficient way to solve the problem using “frequency counter objects”. This is a very handy technique to have in your problem-solving toolbox.