This is a solution to the https://stackoverflow.com/beta/challenges/79811869/challenge-13-integer-sorting-in-a-grid
Table of contents
- Overview
- The challenge
- Links
- My process
- Built with
- What I learned
- Useful resources
- Author
Overview
In this challenge, we will sort some numbers onto a 6x6 square grid. Each cell will have one number.
Your challenge is to place all the integers into the grid such that
Each row is descendingly sorted (ties are not allowed). For example: 6 5 4 3 2 1 is valid but 6 5 5 5 3 2 is not valid.
Each column is descendingly sorted (ties are not allowed)
or declare this impossible.
Example on a 3x3 grid: Given these numbers to sort [95, 75, 75, 74, 74, 74, 54, 45, 40]
A valid response would be [[95, 75, 74], [75, 74, 54], [74, 45, 40]]
In the attached file, we have 100 sets of 36 random integers. The integers are between 0 and 99. For each set, return either a valid sorting on a 6x6 grid or declare it impossible.
Please also return the total count of cases for which the sorting was impossible.
Links Solution URL: [https://github.com/mariyacherian/Stack-Overflow-Challenge---Challenge-13-Integer-sorting-in-a-grid/tree/main]
What I learned
-
While doing this I want to iterate over 2 loops and in some scenario i want to exit from both of this loop i used break for that but it fails.Using break we can exit from the inner loop but outer loop continues. Then I got solution to this by Labeled Break.A labeled break will terminate the outer loop instead of just the inner loop
-
The dafault value of int array is 0 i have tried with this but when 0 comes in the input i have to handle this so i have set -1 in the matrix as default value. Useful resources https://www.baeldung.com/java-breaking-out-nested-loop
Author
Mariya Cherian