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

前端 未结 13 1524
误落风尘
误落风尘 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:11

    -Telling from the perspective of C. -You can have an int 3-d array results[10][10][10]; -Go from 0th location to n-4th location, where n being the size of the string array. -On each location, check the current, next and next's next. -Increment the cntr as resutls[current][next][next's next]++; -Print the values of

    results[1][2][3]
    results[2][3][4]
    results[3][4][5]
    results[4][5][6]
    results[5][6][7]
    results[6][7][8]
    results[7][8][9]
    

    -It is O(n) time, there is no comparisons involved. -You can run some parallel stuff here by partitioning the array and calculating the matches around the partitions.

提交回复
热议问题