Posts

Showing posts from September 15, 2013

Write a program to get the subsequence of a bit 1 and 0 given in a array of bits.

/*  *Write a program to get the subsequence of a bit 1 and 0 given in a array of bits.(Equal No. of 1's and 0's)   For example :  array={1,0,1,1,0,1,1}   Output={1,0,1,0}                 array={1,1,0,1,0,0,1,1} Output={1,1,0,1,0,0}  */ package assignment1; import java.util.ArrayList; /**  * @author snlkjha  */ public class SubSequences {          public static ArrayList<Integer> subsequence(int a[]){    // Array a contains values in the form of 1's and 0's                 ArrayList<Integer> sub=new ArrayList<>();         int count1=0,count0=0,min;         for(int i=0;i<a.length;i++){             if(a[i]==1) count1++;   // counting No of 1's             else count0++;         ...