Given a string of a million numbers, return all repeating 3 digit numbers

前端 未结 13 1446
误落风尘
误落风尘 2020-12-22 15:41

I had an interview with a hedge fund company in New York a few months ago and unfortunately, I did not get the internship offer as a data/software engineer. (They also asked

相关标签:
13条回答
  • 2020-12-22 16:18

    As mentioned in another answer, you cannot do this algorithm in constant time, because you must look at at least n digits. Linear time is the fastest you can get.

    However, the algorithm can be done in O(1) space. You only need to store the counts of each 3 digit number, so you need an array of 1000 entries. You can then stream the number in.

    My guess is that either the interviewer misspoke when they gave you the solution, or you misheard "constant time" when they said "constant space."

    0 讨论(0)
提交回复
热议问题