Блог пользователя sore_loser

Автор sore_loser, история, 9 лет назад, По-английски

Suppose, I have a matrix with N rows and M columns. I want to find the number that appears most along with their frequencies for each row and each column. If there are multiple such numbers, any of them will do.

For example, let the matrix be a 4*3 matrix like this:

9 4 4

5 4 2

1 3 1

1 1 2

then I will perform calculation in these four arrays as follows:

rowval = {4,2,1,1} [ith value denotes the number that appears most in ith row]

rowfrq = {2,1,2,2} [the number of time the the max value of ith row appears]

colval = {1,4,2} [ith value denotes the number that appears most in ith column]

colfrq = {2,2,2} [the number of time the the max value of ith column appears]

What will be the most efficient way of performing this calculation? N*M can be upto 10^6 and the values of the matrix can be upto 10^6 as well . I was thinking of using map, but cannot understand what the complexity will be. Of course if there is a better approach, please help :)

Полный текст и комментарии »

  • Проголосовать: нравится
  • -19
  • Проголосовать: не нравится

Автор sore_loser, история, 9 лет назад, По-английски

I need some help with this problem

Snakes and Ladders

Actually, I think I have got quite a hold of it. What I can't get my head around is as there may be n(n-1)/2 possible pairs at the max, how can I take all these possible pairs in less than O(N^2) time? The constraints clearly mean that O(N^2) won't do. Or is there some way to bypass this calculation? (which I am quite sure there isn't)

Полный текст и комментарии »

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится