Skip to content

Conversation

@altay9
Copy link
Collaborator

@altay9 altay9 commented Jun 20, 2021

Resolves: #213

  • We can imagine a square at the top left of the matrix.
  • We can assume that the matrix itself is a product of copying this square multiple times and cutting the edges according to the matrix size.
  • Then we can assign an id for each tile of the square. (Just like we have done in 305. Number of Islands II #329 with getNodeId())

We need to count how many times each tile id could repeat (if the tile would have been selected to set 1 in it)
Then we select top n (=maxOnes) tiles that repeat most in order to get the maximum benefit.
(We could also use a PQ instead of sorting the array.)

IMG-1670

Copy link
Collaborator

@ErdemT09 ErdemT09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to me like a combination of graph and array problems. The image and the concise explanation helps a lot with the understanding. Once again, thank you for your contribution.
Approved.

@altay9 altay9 merged commit ce2f532 into master Jun 20, 2021
@altay9 altay9 deleted the MaximumNumberofOnes branch June 20, 2021 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1183. Maximum Number of Ones

3 participants