Skip to content

Commit f555945

Browse files
committed
Merge pull request blakeembrey#150 from Widea/patch-1
Update to handle an edge case
2 parents b8edc89 + 3c9d6ed commit f555945

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

solutions/java/ConvertArray.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public int getOriginalIndex(int currentIndex, int length) {
88
}
99

1010
public int[] convert(int[] input) {
11+
// When array size is less than 3, returns an error.
12+
if (input.length % 3 != 0 ) {
13+
System.out.println("Error! Array cannot be divided into three equal parts");
14+
return;
15+
}
1116
for (int i = 0; i < input.length; ++i) {
1217
int originalIndex = getOriginalIndex(i, input.length/3);
1318
while (originalIndex < i) {

0 commit comments

Comments
 (0)