Form Array by Concatenating Subarrays of Another Array LeetCode solution in Java
1class Solution {23public int search(int[] group, int[] nums, int start, int end) {4int i = start, j = 0;5while (i < end && j < group.length) {6if (nums[i] == group[j]) {7i++;8j++;910if (j == group.length) return i;11} else {12i = i - j + 1;13j = 0;14}15}16return -1;17}1819public boolean canChoose(int[][] groups, int[] nums) {20int start = 0, end = nums.length;2122for (int[] group : groups) {23start = search(group, nums, start, end);24if (start == -1) return false;25}2627return true;28}29}