Following are the test cases
Test cases | Result | Status |
---|---|---|
tripleUp({1,2,3,7,5,9}) | true | OK |
tripleUp({1,4,5,6,2}) | true | OK |
tripleUp({1,2,4,5}) | false | OK |
Java solution
package test;
public class Program15 {
public static void main(String[] args) {
int a[] = {1,2,3,7,5,9};
int b[] = {1,4,5,6,2};
int c[] = {1,2,4,5};
Program15.tripleUp(a);
Program15.tripleUp(b);
Program15.tripleUp(c);
}
public static boolean tripleUp(int[] nums) {
for (int i = 0; i < nums.length-2; i++) {
if (nums[i+1] == nums[i] + 1 && nums[i+2] == nums[i] + 2) {
return true;
}
}
return false;
}
}
Javascript solution
const tripleUp = (nums) => {
for (let i = 0; i < nums.length; i++) {
if (nums[i+1] === nums[i] + 1 && nums[i+2] === nums[i] + 2) {
return true;
}
}
return false;
}
console.log(tripleUp([1,2,3,7,5,9])); //true
console.log(tripleUp([1,4,5,6,2])); //true
console.log(tripleUp([1,2,4,5])); //false