fix: improve comments
This commit is contained in:
@@ -28,21 +28,38 @@ public class MainExercises
|
||||
|
||||
|
||||
/*
|
||||
given a matrix of random integers, you should do spiral traversal in it
|
||||
e.g. if the matrix is as shown below:
|
||||
1 2 3
|
||||
4 5 6
|
||||
7 8 9
|
||||
then the spiral traversal of that is:
|
||||
{1, 2, 3, 6, 9, 8, 7, 4, 5}
|
||||
SPIRAL TRAVERSAL OF A RECTANGULAR MATRIX
|
||||
|
||||
so you should walk in that matrix in a curl and then add the numbers in order you've seen them in a 1D array
|
||||
*/
|
||||
public int[] spiralTraversal(int[][] values, int rows, int cols) {
|
||||
Given a rectangular matrix (2D array) of integers, this method traverses
|
||||
it in a spiral order (clockwise from outside to inside) and returns
|
||||
the elements as a 1D array.
|
||||
|
||||
EXAMPLE:
|
||||
Input matrix:
|
||||
1 2 3
|
||||
4 5 6
|
||||
7 8 9
|
||||
|
||||
Spiral order: start at top-left (1), go right →, then down ↓,
|
||||
then left ←, then up ↑, then repeat inward.
|
||||
|
||||
Result: {1, 2, 3, 6, 9, 8, 7, 4, 5}
|
||||
|
||||
so you should walk in that matrix in a curl and then add the numbers in order you've seen them in a 1D array
|
||||
|
||||
RECTANGULAR MATRIX ASSUMPTION:
|
||||
This method assumes the input matrix is RECTANGULAR (all rows have
|
||||
the same number of columns). In Java, we can verify this because
|
||||
2D arrays might be jagged (rows of different lengths).
|
||||
|
||||
IMPORTANT: In Java, we do NOT need to pass rows and cols!
|
||||
The 2D array 'matrix' knows its own dimensions:
|
||||
- Number of rows: matrix.length
|
||||
- Number of columns: matrix[0].length (if rectangular)
|
||||
*/
|
||||
public int[] spiralTraversal(int[][] matrix) {
|
||||
// todo
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -61,14 +78,18 @@ public class MainExercises
|
||||
2, 1, 1
|
||||
1, 1, 1, 1
|
||||
|
||||
note: as you can see in examples, we want to generate distinct summations, which means 1, 2 and 2, 1 are no different
|
||||
you should generate all partitions of the input number and
|
||||
Note: As you can see in the examples, we want to generate distinct partitions,
|
||||
which means 1,2 and 2,1 are not different — they count as the same combination.
|
||||
|
||||
hint: you can measure the size and order of arrays by finding the pattern of partitions and their number
|
||||
trust me, that one's fun and easy :)
|
||||
You should generate all partitions of the input number.
|
||||
|
||||
if you're familiar with lists and arraylists, you can also edit method's body to use them instead of array
|
||||
Hint: You can determine the size and order of the arrays by finding the pattern
|
||||
of partitions and their count. Trust me, this one's fun and easy :)
|
||||
|
||||
If you're familiar with Lists and ArrayLists, you can also edit the method's
|
||||
body to use them instead of arrays.
|
||||
*/
|
||||
|
||||
public int[][] intPartitions(int n) {
|
||||
// todo
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user