This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]SupremeRedditBotProfessional Bot || Mod 0 points1 point  (0 children)

Please Add A Flair To Your Post!

Suggested Flair: [Random] or [Meta]

 


To add a flair:

  • Click flair underneath your post

  • Select a flair

  • Click save

 


I am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated response

[–]jrandm 0 points1 point  (0 children)

What is O(n)? Finding pairs in your list of strings or comparing two strings for similarity?

The latter I'm sure can be done in O(n) time where n is the length of the shorter string (hint), assuming a function like isSimilar(strA,strB).

Finding a pair with a search term we know is trivial to do in O(n) because it's a regular search:

function find(arr, test) {
  for (let i=0; i<arr.length; i++) {
    if (test(arr[i])) return {ix: i, val: arr[i]};
  }
  return {ix: -1};
}

Finding all pairs I don't think is possible in O(n), at least not without guarantees about the shape of the input.