title: Closest multiplication value from array
body: <p>I have an array of integers and a number K is given, i need to find the closest value (also the elements of arrays) to K which can be generated by multiplying various numbers from array.</p>
  
  <p>eg.
  arr - 2, 2, 5, 5, 7
  K = 30</p>
  
  <p>Output - 2*2*7 = 28.</p>
  
  <p>I can't think of any better solution than an exponential one where i make different permutation of elements and check for the closest value. Please suggest a better (may be dynamic programming) approach to solve it efficiently.</p>
  
  <p>This is what i wrote :-</p>
  
  <pre><code>void findClosestValue(int arr[], int start, int end, int k, int&amp; diff, int mul)
  {
      if(start&lt;=end+1)
      {
          cout&lt;&lt;"  start = "&lt;&lt;start&lt;&lt;"  end = "&lt;&lt;end&lt;&lt;"  diff = "&lt;&lt;diff&lt;&lt;"  k = "&lt;&lt;k&lt;&lt;"  mul = "&lt;&lt;mul&lt;&lt;endl;
          if(diff &gt; differ(k, mul))
              diff = differ(k, mul);
          findClosestValue(arr, start+1, end, k, diff, mul*arr[start]);
          findClosestValue(arr, start+1, end, k, diff, mul);
      }
      else
          return;
  }
  </code></pre>
  
  <p>Call for this function was :- </p>
  
  <p>int val = 100000000;</p>
  
  <p>findClosestValue(arr, 0, size-1, k, val, 1);</p>