Shivam Patel 6 anni fa
parent
commit
10172f838b

BIN
.DS_Store Vedi File


+ 1
- 0
.idea/.name Vedi File

@@ -0,0 +1 @@
1
+FundamentalDrills-Part1

+ 16
- 0
.idea/compiler.xml Vedi File

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="CompilerConfiguration">
4
+    <annotationProcessing>
5
+      <profile name="Maven default annotation processors profile" enabled="true">
6
+        <sourceOutputDir name="target/generated-sources/annotations" />
7
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8
+        <outputRelativeToContentRoot value="true" />
9
+        <module name="FundamentalDrills-Part1" />
10
+      </profile>
11
+    </annotationProcessing>
12
+    <bytecodeTargetLevel>
13
+      <module name="FundamentalDrills-Part1" target="1.5" />
14
+    </bytecodeTargetLevel>
15
+  </component>
16
+</project>

+ 13
- 0
.idea/misc.xml Vedi File

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="MavenProjectsManager">
4
+    <option name="originalFiles">
5
+      <list>
6
+        <option value="$PROJECT_DIR$/pom.xml" />
7
+      </list>
8
+    </option>
9
+  </component>
10
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_10" project-jdk-name="10" project-jdk-type="JavaSDK">
11
+    <output url="file://$PROJECT_DIR$/classes" />
12
+  </component>
13
+</project>

+ 8
- 0
.idea/modules.xml Vedi File

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/FundamentalDrills-Part1.iml" filepath="$PROJECT_DIR$/FundamentalDrills-Part1.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
.idea/vcs.xml Vedi File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 16
- 0
FundamentalDrills-Part1.iml Vedi File

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
4
+    <output url="file://$MODULE_DIR$/target/classes" />
5
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
+    <content url="file://$MODULE_DIR$">
7
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

BIN
src/.DS_Store Vedi File


BIN
src/main/.DS_Store Vedi File


BIN
src/main/java/.DS_Store Vedi File


BIN
src/main/java/io/.DS_Store Vedi File


+ 133
- 8
src/main/java/io/zipcoder/ArrayDrills.java Vedi File

@@ -1,5 +1,7 @@
1 1
 package io.zipcoder;
2 2
 
3
+
4
+
3 5
 public class ArrayDrills {
4 6
 
5 7
 
@@ -10,7 +12,17 @@ public class ArrayDrills {
10 12
      *           firstLast(6, [1,2,3]); // Should return false
11 13
      */
12 14
     public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
15
+        boolean contain = false;
16
+
17
+        for(int i = 0; i < input.length; i++){
18
+            if(input[0].equals(value) || input[input.length - 1].equals(value)){
19
+                contain = true;
20
+            }
21
+
22
+        }
23
+
24
+
25
+        return contain;
14 26
     }
15 27
 
16 28
     /**
@@ -19,7 +31,21 @@ public class ArrayDrills {
19 31
      *           sameFirstLast([1,2,1]); // Should return true
20 32
      */
21 33
     public Boolean sameFirstLast(Integer[] input){
22
-        return null;
34
+        boolean contain = false;
35
+        for(int i = 0; i<input.length; i++){
36
+            if(input[0] == input[input.length-1]){
37
+                contain = true;
38
+
39
+            }
40
+            else{
41
+                contain = false;
42
+            }
43
+
44
+
45
+        }
46
+
47
+
48
+        return contain;
23 49
     }
24 50
 
25 51
 
@@ -30,7 +56,18 @@ public class ArrayDrills {
30 56
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 57
      */
32 58
     public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
59
+        boolean contain = false;
60
+
61
+        if(input1[0] == input2[0] || input1[input1.length-1] == input2[input2.length-1]){
62
+                contain = true;
63
+            }
64
+            else{
65
+                contain = false;
66
+            }
67
+
68
+
69
+
70
+        return contain;
34 71
     }
35 72
 
36 73
     /**
@@ -39,7 +76,19 @@ public class ArrayDrills {
39 76
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 77
      */
41 78
     public Integer[] rotateLeft(Integer[] input){
42
-        return null;
79
+        Integer[] newArr = new Integer[input.length];
80
+        int temp = input[0];
81
+
82
+        for(int i = 0; i<input.length-1; i++) {
83
+
84
+            newArr[i] = input[i + 1];
85
+
86
+
87
+        }
88
+
89
+        newArr[input.length-1] = temp;
90
+
91
+        return newArr;
43 92
     }
44 93
 
45 94
 
@@ -50,7 +99,26 @@ public class ArrayDrills {
50 99
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51 100
      */
52 101
     public Integer[] maxValue(Integer[] input){
53
-        return null;
102
+
103
+        Integer[] output = new Integer[input.length];
104
+        int max = input[0];
105
+        for(int i = 0; i < input.length; i++){
106
+            if( input[i] > max ){
107
+                max = input[i];
108
+
109
+
110
+            }
111
+
112
+
113
+        }
114
+        for(int j = 0; j < output.length; j++){
115
+            output[j] = max;
116
+
117
+
118
+        }
119
+
120
+
121
+        return output;
54 122
     }
55 123
 
56 124
 
@@ -61,9 +129,28 @@ public class ArrayDrills {
61 129
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 130
      */
63 131
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
132
+
133
+
134
+        Integer[] mid = new Integer[2];
135
+        mid[0] = middle(input1);
136
+        mid[1] = middle(input2);
137
+
138
+
139
+
140
+    return mid;
141
+
142
+
65 143
     }
144
+    private int middle(Integer[] input) {
145
+        int value = 0;
146
+        if (input.length % 2 == 0) {
66 147
 
148
+            value = input[input.length / 2] + input[(input.length / 2) - 1];
149
+        } else {
150
+            value =  input[input.length / 2];
151
+        }
152
+        return value;
153
+    }
67 154
 
68 155
     /**
69 156
      * Start with 2 int arrays, a and b, each length 2.
@@ -71,7 +158,30 @@ public class ArrayDrills {
71 158
      * Return the array which has the largest sum. In event of a tie, return a.
72 159
      */
73 160
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
161
+
162
+        Integer[] biggest = new Integer[a.length];
163
+        int suma = 0;
164
+        int sumb = 0;
165
+        for(Integer i : a){
166
+            suma += i;
167
+
168
+        }
169
+        for(Integer j : b){
170
+
171
+            sumb += j;
172
+        }
173
+        if (suma >= sumb){
174
+
175
+            biggest = a;
176
+
177
+        }
178
+        else{
179
+            biggest = b;
180
+        }
181
+
182
+
183
+
184
+        return biggest;
75 185
     }
76 186
 
77 187
     /**
@@ -81,6 +191,21 @@ public class ArrayDrills {
81 191
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 192
      */
83 193
     public Integer[] midThree(Integer[] nums){
84
-        return null;
194
+
195
+        Integer[] mid3 = new Integer[3];
196
+        int count = 0;
197
+        for(int i = 0; i < nums.length; i++){
198
+
199
+            if(i >= (nums.length/2)-1 && i <= (nums.length/2)+1){
200
+
201
+              mid3[count] = nums[i];
202
+
203
+              count ++;
204
+            }
205
+
206
+        }
207
+
208
+
209
+        return mid3;
85 210
     }
86 211
 }

+ 2
- 2
src/test/java/io/zipcoder/ArrayDrillsTest.java Vedi File

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder;
2 2
 
3
-import com.sun.tools.corba.se.idl.InterfaceGen;
3
+//import com.sun.tools.corba.se.InterfaceGen;
4 4
 import org.junit.Assert;
5 5
 import org.junit.Before;
6 6
 import org.junit.Test;
@@ -179,7 +179,7 @@ public class ArrayDrillsTest {
179 179
     public void biggerTwo3(){
180 180
         Integer[] inputArray1 = {-1 ,20};
181 181
         Integer[] inputArray2 = {2, 15};
182
-        Integer[] expected = {1,20};
182
+        Integer[] expected = {-1,20};
183 183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
184 184
         Assert.assertArrayEquals(expected, actual);
185 185
     }

BIN
target/classes/io/zipcoder/ArrayDrills.class Vedi File


BIN
target/test-classes/io/zipcoder/ArrayDrillsTest.class Vedi File