Skip to content
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
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/Problem1.class
/Solution.class
/Problem2.class
/Problem3.class
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Array1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
18 changes: 18 additions & 0 deletions Problem1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int[] productExceptSelf(int[] num) {
int n= num.length;
int[] result= new int[n];
result[0]=1;
int lp=1;
for(int i=1;i<n;i++){
lp=lp*num[i-1];
result[i]= lp;
}
int rp=1;
for(int i=n-2;i>=0;i--){
rp=rp*num[i+1];
result[i]=result[i]*rp;
}
return result;
}
}
42 changes: 42 additions & 0 deletions Problem2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Problem2 {
public int[] findDiagonalOrder(int[][] mat) {
int m= mat.length;
int n= mat[0].length;
int r=0;
int c=0;
boolean dir= true;
int[] result= new int[m*n];
for(int i=0;i<m*n;i++){
result[i]= mat[r][c];
if(dir){
if(c==n-1){
r++;
dir= false;
}
else if(r==0){
c++;
dir= false;
}
else{
r--;
c++;
}
}
else{
if(r== m-1){
c++;
dir= true;
}
else if(c==0){
r++;
dir= true;
}
else{
r++;
c--;
}
}
}
return result;
}
}
37 changes: 37 additions & 0 deletions Problem3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.*;

class Problem3 {
public List<Integer> spiralOrder(int[][] matrix) {
int m= matrix.length;
int n= matrix[0].length;
int top=0;
int left=0;
int right= n-1;
int bottom= m-1;
List<Integer> result= new ArrayList<>();
while(left<=right && top<= bottom){
for(int i=left;i<=right;i++){
result.add(matrix[top][i]);
}
top++;
for(int i=top;i<=bottom;i++){
result.add(matrix[i][right]);
}
right--;
if(top<=bottom){
for(int i=right; i>=left;i--){
result.add(matrix[bottom][i]);
}
bottom--;
}
if(left<=right){
for(int i=bottom;i>=top;i--){
result.add(matrix[i][left]);
}
left++;
}
}
return result;

}
}