Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Spiral Matrix code in java #1271

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Intermediate/algorithms/Spiral matrix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.*;

public class SpiralOrderRunner {
public static void main(String[] args) {
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};

Solution solution = new Solution();
List<Integer> result = solution.spiralOrder(matrix);

System.out.println("Spiral order traversal: " + result);
}
}

class Solution {
public List<Integer> spiralOrder(int[][] matrix) {
ArrayList<Integer> list = new ArrayList<>();
int dir = 0, top = 0, left = 0, bottom = matrix.length - 1, right = matrix[0].length - 1;

while (top <= bottom && left <= right) {
// Moving left to right
if (dir == 0) {
for (int i = left; i <= right; i++) {
list.add(matrix[top][i]);
}
top++; // move the top boundary down
dir = 1;
}
// Moving top to bottom
else if (dir == 1) {
for (int i = top; i <= bottom; i++) {
list.add(matrix[i][right]);
}
right--; // move the right boundary left
dir = 2;
}
// Moving right to left
else if (dir == 2) {
for (int i = right; i >= left; i--) {
list.add(matrix[bottom][i]);
}
bottom--; // move the bottom boundary up
dir = 3;
}
// Moving bottom to top
else if (dir == 3) {
for (int i = bottom; i >= top; i--) {
list.add(matrix[i][left]);
}
left++; // move the left boundary right
dir = 0; // reset the direction to start again
}
}

return list;
}
}
54 changes: 54 additions & 0 deletions Intermediate/html-css-snippets/Diet Chart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>Diet Chart</title>
</head>
<body>
<h1 style="color:orange; font-size:50px; text-align:center;">Diet Chart</h1>
<table rules="all" frame="box" bordercolordark="#1D7874" cellpadding="10px" width="80%">
<tr>
<td style="color:darkblue">Meal/Day of the week</td>
<td style="color:brown">Monday</td>
<td style="color:brown">Tuesday</td>
<td style="color:brown">Wednesday</td>
<td style="color:brown">Thursday</td>
<td style="color:brown">Friday</td>
</tr>
<tr>
<td style="color:blueviolet">Breakfast</td>
<td style="color:cadetblue">1 bowl of poha or daliya</td>
<td style="color:cadetblue">oats porridge</td>
<td style="color:cadetblue">idli-sambhar</td>
<td style="color:cadetblue">1 egg-omlette</td>
<td style="color:cadetblue">1 besan chilla</td>
</tr>
<tr>
<td style="color:blueviolet">Lunch</td>
<td style="color:cadetblue">2 chapatti with dal and curd</td>
<td style="color:cadetblue">2 chapatti with sabzi and salad</td>
<td style="color:cadetblue">1 bajra roti with dal and salad</td>
<td style="color:cadetblue">1 chapatti and rice with chole</td>
<td style="color:cadetblue">2 chapatti with sabzi and curd</td>
</tr>
<tr>
<td style="color:blueviolet">Snack</td>
<td style="color:cadetblue">1 bowl of cut fruits</td>
<td style="color:cadetblue">1 glass fruit juice</td>
<td style="color:cadetblue">1 bowl soup</td>
<td style="color:cadetblue">1 bowl sprouts salad</td>
<td style="color:cadetblue">1 glass coconut water</td>
</tr>
<tr>

<td style="color:blueviolet">Dinner</td>
<td style="color:cadetblue">2 chapatti with dal</td>
<td style="color:cadetblue">2 chapatti with palak paneer</td>
<td style="color:cadetblue">1 bajra roti with dal</td>
<td style="color:cadetblue">1 chapatti and rice with chole</td>
<td style="color:cadetblue">2 chapatti with sabzi</td>
</tr>
</table>
<h2 style="color:brown;font-size: 20px;">Hope it helps, Thank You</h2>
<h3 style="color:brown;font-size: 20px;">For more information please refer to link mentioned below. <a href="https://www.healthline.com/nutrition/how-to-lose-weight-as-fast-as-possible">Want to lose wait fast</a></h3>
</body>
</html>