title: Generating all the increasing digit numbers
body: <p>I came across the following question for an interview.</p>
  
  <p>For a given number of digits, generate all the numbers such that the value of a higher order digit is less than a lower order digit.</p>
  
  <p>145 // 1 &lt; 4 &lt; 5</p>
  
  <p>Is there a better (efficient) way to do this than the one I have come up with:</p>
  
  <pre><code>public static void GenerateSpecialNumbers(int noDigits)
  {           
      int prod = 1;
      for(int i=0; i &lt; noDigits; i++)
      {
          prod = prod * 10;
      }
      int minValue = prod/10;
      int maxValue = prod - 1;        
  
      for(int i = minValue; i &lt; maxValue; i++)
      {
          bool isValid = true;
  
          int num  = i;
          int max = int.MaxValue;
  
          while(num &gt; 0)
          {
              int digit = num % 10;
              if(digit &gt;= max)
              {
                  isValid = false;
                  break;
              }
              max = digit;            
  
              num = num/10;
          }
  
          if(isValid)
              Console.WriteLine(i);               
      }
  }
  </code></pre>
  
  <p>EDIT:
  Output for 3 digits:</p>
  
  <p>123
  124
  125
  126
  127
  128
  129
  134
  135
  136
  137
  138
  139
  145
  146
  147
  148
  149
  156
  157
  158
  159
  167
  168
  169
  178
  179
  189
  234
  235
  236
  237
  238
  239
  245
  246
  247
  248
  249
  256
  257
  258
  259
  267
  268
  269
  278
  279
  289
  345
  346
  347
  348
  349
  356
  357
  358
  359
  367
  368
  369
  378
  379
  389
  456
  457
  458
  459
  467
  468
  469
  478
  479
  489
  567
  568
  569
  578
  579
  589
  678
  679
  689
  789</p>