Following are the test cases
Test cases | Result | Status |
---|---|---|
haveThree({12,3,4,3,88,3}) | true | OK |
haveThree({22,3,3,3,17,3}) | false | OK |
haveThree({3,4,3,6,3,7}) | true | OK |
Java solution
package test;
public class Program20 {
public static void main(String[] args) {
// 3, 1, 3, 1, 3
int a[] = {3,4,3,6,3,7};
Program20.haveThree(a);
}
public static boolean haveThree(int[] nums) {
for (int i = 1; i < nums.length-1; i++) {
if (nums[i] == 3 && nums[i-1] != 3 && nums[i+1] != 3) {
return true;
}
}
return false;
}
}