Question: Returns whether every 4 in the array is either immediately preceded by a 1, immediately followed by a 2, or both. all142([1, 4, 2]) true

Returns whether every 4 in the array is either immediately preceded by a 1, immediately followed by a 2, or both.

all142([1, 4, 2]) true all142([4]) false all142([1]) true

Write a java source code

boolean all142(int[] nums) {

}

These are the test cases

 Returns whether every 4 in the array is either immediately preceded

Run true Expected all142([1, 4, 2]) true all142([4]) false all142([1]) true all142([4, 2]) true false true true false all142([4, 3]) false all142([4, 4]) false false all142([1, 4]) true true all142([3, 4]) false false all142([2]) true true all142([3]) true true all142([1, 4, 4, 2]) true true all142([1, 4, 3]) true true all142([3, 4, 2]) true true all142([1, 4, 4, 4, 2]) false true all142([1, 4, 5, 4, 2]) + true true all142([1, 4, 4, 2, 1, 4, 1, 4]) true true all142([1, 4, 2, 4]) false true other tests

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!