Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 testsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started