Skip to content

Commit 04f52b5

Browse files
author
reach2arunprakash
committed
Src codes
1 parent 92332af commit 04f52b5

File tree

555 files changed

+132587
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

555 files changed

+132587
-0
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.class
2+
3+
# Mobile Tools for Java (J2ME)
4+
.mtj.tmp/
5+
6+
# Package Files #
7+
*.jar
8+
*.war
9+
*.ear
10+
11+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12+
hs_err_pid*
13+
/bin/

Aggregate Zeros/.classpath

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
31+
<attributes>
32+
<attribute name="maven.pomderived" value="true"/>
33+
</attributes>
34+
</classpathentry>
35+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
36+
<classpathentry kind="output" path="target/classes"/>
37+
</classpath>

Aggregate Zeros/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

Aggregate Zeros/.project

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Aggregate Zeros</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3+
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.source=1.5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

Aggregate Zeros/ALGORITHM.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Aggregate Zeros after all Non-zero elements maintaining Order of Non-zero elements
2+
===============================================================================
3+
4+
<h3>
5+
Statement :
6+
</h3>
7+
Aggregate all zeros in last of array, such that all non-zero elements are in beginning one after. Also order between non-zero elements is to be maintained.
8+
9+
<h4>
10+
Algorithm :
11+
</h4>
12+
Take two index pointers. First pointing to leftmost index which have zero.
13+
Initially second pointer also points where first points.
14+
Then go on incrementing second pointer, if element under it is non-zero then put it where first
15+
pointer points and increment first pointer by one.
16+
17+
<h4>
18+
Complexity :
19+
</h4>
20+
Time : O(n) <br>
21+
Space : O(1)

Aggregate Zeros/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>in.interview.microsoft</groupId>
4+
<artifactId>aggregate-elements</artifactId>
5+
<version>0.1</version>
6+
<name>Aggregate Elements</name>
7+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package in.interview.microsoft;
2+
3+
/**
4+
* Aggregate all zeros in end.
5+
*
6+
* @author kuldeep
7+
*/
8+
public class Aggregation {
9+
10+
/**
11+
* Aggregate all zeros in end of array.
12+
*
13+
* @param array
14+
* original array
15+
* @return original array with all zeros in last
16+
*/
17+
public static int[] aggregate(int[] array){
18+
19+
// without using temp variable
20+
// int j = 0;
21+
// while (array[j] != 0) j++;
22+
//
23+
// for (int i = j; i < array.length; i++) {
24+
// if (array[i] != 0) {
25+
// array[j] = array[i];
26+
// array[i] = 0;
27+
// j++;
28+
// }
29+
// }
30+
31+
for(int i = 0, j = 0; j < array.length; j++) {
32+
if (array[j] != 0) {
33+
int temp = array[j];
34+
array[j] = array[i];
35+
array[i] = temp;
36+
i++;
37+
}
38+
}
39+
40+
return array;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package in.interview.microsoft;
2+
3+
import static org.junit.Assert.*;
4+
5+
import org.junit.Test;
6+
7+
/**
8+
* Junit test for {@link Aggregation}.
9+
*
10+
* @author kuldeep
11+
*/
12+
public class AggregationTest {
13+
14+
@Test
15+
public void testAggregate() {
16+
17+
int[] array = new int[]{1,0,2,0,3,0,0,4,5,6,7,0,0,0};
18+
19+
int[] expected = new int[]{1,2,3,4,5,6,7,0,0,0,0,0,0,0};
20+
Aggregation.aggregate(array);
21+
assertArrayEquals(expected, array);
22+
23+
array = Aggregation.aggregate(new int[]{0,0,0,0,1,2,3,7,5,3,0,0,0});
24+
assertArrayEquals(new int[]{1,2,3,7,5,3,0,0,0,0,0,0,0}, array);
25+
}
26+
27+
}

0 commit comments

Comments
 (0)