Shortest Non-Continuous Subsequence

Given an array: 1,2,3 ,5,8,7,6,9,5,7,3,0,5
subarry:5,7

Find the subarray in the large array and return the minimum length and index where you can find the subarray. Note: that the subarray may be present in the large array non-contiguous.

In the above case : the answer is length = 2 and
index = 8


public static void moveZeroes(int[] a){
  	int pos = 0;
  	for(int i = 0; i < a.length; i++)
  		if(a[i] != 0)
  			a[pos++] = a[i];
  	for(int i = pos; i < a.length; i++)
  		a[i] = 0;
  }
Comments