title: Calculating subsets of an array within a given range?
body: <p>Given an array of n numbers, how can we calculate the subsets of that array (0 based indexed) in a given range i.e starting from ith index to jth index. I tried using bitmasking but couldn't figure out how to solve this because of the range.</p>
  
  <p>For example, if array a is a = [2 6 9 1 7] and the given range is 1 to 3, then the answer will be = [6], [9], [1], [6 9], [6 1], [9 1], [6 9 1]</p>
  
  <p>Here is the function which calculates all the subsets of array and I'm unsure how to use that range constrain.</p>
  
  <pre><code>private static void findSubsets(int array[])
  {
      int numOfSubsets = 1 &lt;&lt; array.length; 
  
      for(int i = 0; i &lt; numOfSubsets; i++)
      {
          int pos = array.length - 1;
          int bitmask = i;
  
          System.out.print("{");
          while(bitmask &gt; 0)
          {
              if((bitmask &amp; 1) == 1)
              System.out.print(array[pos]+",");
              bitmask &gt;&gt;= 1;
              pos--;
          }
          System.out.print("}");
      }
  }
  </code></pre>