re: Breaking Down JavaScript Solutions To Common Algorithmic Questions (Part 1) VIEW POST

FULL DISCUSSION
 

A great demonstration for beginners, but the terms "brute force" and "optimized" are quite misleading.

Brute force usually means exhaustive search, for example in password cracking, where all the possible combinations of letters are tried. Better term would be "naive".

Optimized usually means faster, better than naive simple method. In these examples no optimized solution is faster than the "brute force". It's still the same asymptotic complexity, but usually more operations, so normally it'd be slower. It's optimized for code size, I give you that.

Actually, all those "ugly", C style version for for loops and nester for loops usually perform better than their functional equivalents, because they usually allocate less memory to store temporaries. For example:

const arrOfLengths = arrOfWords.map(item => item.length);

creates an array to store lengths of words. This could be avoided by calculating the maximum on the fly, like in the "brute force" solution. Imagine a situation where you only have memory to store the original list of words, say it's 2GB long. It's still O(n), but requires double the memory.

 

yes correct! Also in the interviews they(recruiters) would expect us to write the code without using in built methods.

 

they would expect us to write the code without using in built methods

They would? Since when? Where?

In most of the top companies the interviewers will ask us to write the code without using any in build methods.

 

but while working in a software company we should use the in built methods for code readability.

code of conduct - report abuse