feat: add MainExercises
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
public class MainExercises
|
||||
{
|
||||
/*
|
||||
you should create a triangle with "*" and return a two-dimensional array of characters based on that
|
||||
the triangle's area is empty, which means some characters should be " "
|
||||
|
||||
example 1, input = 3:
|
||||
*
|
||||
**
|
||||
***
|
||||
|
||||
example 2, input = 5:
|
||||
*
|
||||
**
|
||||
* *
|
||||
* *
|
||||
*****
|
||||
|
||||
the output has to be a two-dimensional array of characters, so don't just print the triangle!
|
||||
*/
|
||||
public char[][] generateTriangle(int n) {
|
||||
|
||||
// todo
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
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}
|
||||
|
||||
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) {
|
||||
|
||||
// todo
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
integer partitioning is a combinatorics problem in discreet maths
|
||||
the problem is to generate sum numbers which their summation is the input number
|
||||
|
||||
e.g. 1 -> all partitions of integer 3 are:
|
||||
3
|
||||
2, 1
|
||||
1, 1, 1
|
||||
|
||||
e.g. 2 -> for number 4 goes as:
|
||||
4
|
||||
3, 1
|
||||
2, 2
|
||||
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
|
||||
|
||||
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 :)
|
||||
|
||||
if you're familiar with lists and arraylists, you can also edit method's body to use them instead of array
|
||||
*/
|
||||
public int[][] intPartitions(int n) {
|
||||
// todo
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static void main()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user