Problem Statement:
For a given input print concentric squares on console.
Solution :
Multiple solutions are available for this problem, but we will solve this without any additional space.
Here the idea is to calculate the minimum depth of each square from outer boundary.
Solution was suggested by Ashish Mishra
Please post your suggestions and comments.
Happy Coding !! :)
For a given input print concentric squares on console.
Fig1 : Concentric Squares |
Solution :
Multiple solutions are available for this problem, but we will solve this without any additional space.
Here the idea is to calculate the minimum depth of each square from outer boundary.
Answer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public static void concentricSquare(int num) { int size = 2*num-1; for (int row = 1; row <= size; row++) { for (int col = 1; col <= size; col++) { int rowDepth = num - 1 - abs(row - num); int colDepth = num - 1 - abs(col - num); int minDepth = min(rowDepth, colDepth); System.out.print(num - minDepth + " "); } System.out.println(); } } |
Solution was suggested by Ashish Mishra
Please post your suggestions and comments.
Happy Coding !! :)
supreme hoodie
ReplyDeletecurry shoes
golden goose starter
vapormax
converse shoes
coach outlet store online
balenciaga shoes
converse shoes
adidas tubular
kyrie 6
This problem, rooted in number theory and algorithms, seeks to identify a subarray where the sum of its elements is evenly divisible. Having Bad Games Solving it requires careful analysis of remainders and modular arithmetic, showcasing the interplay between mathematics and programming.
ReplyDelete