Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Monk in the Grass Fields - HackerEarth (Sorting)

$
0
0

Problem link: https://www.hackerearth.com/code-monk-sorting/algorithm/monk-in-the-grass-fields/

My code: https://www.hackerearth.com/submission/2962880/

My logic:

1) Find sum of elements in each row and store in an array called rowsum.

2) Find sum of elements in each column and store in an array called colsum.

3) Sort rowsum and colsum

4) Choose the row sum or column sum with the least value. Let's say it's a row which has the least value. Increase that particular row sum by n, and increment all colsum values by 1. Can happen vice versa.

5) Sort. Repeat.

Might not be the most efficient, but it seems to be wrong as such. I don't really get the idea described in the editorial in the problem link either. So could someone please clarify why my logic is wrong and in what angle I should approach the problem instead (just a hint)?


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>