title: print a matrix that is spiraling out from a given row and column using multi-threading
body: <p>I was recently asked this question in an interview. After spending hours, I did come up with a single threaded implementation but, I feel it is inefficient and I have no clue about how to make it multi-threaded. </p>
  
  <p>Here is my implementation:</p>
  
  <pre><code>public List&lt;Integer&gt; print(int[][] input, int row, int col) {
      int n = input.length;
      List&lt;Integer&gt; result = new ArrayList&lt;&gt;(n * n);
      int i = row;
      int j = col;
      int steps = 1;
      int k = 0;
      while (true) {
  
          k = steps;
  
          while (k &gt; 0) {
              if (inBounds(i, j, n)) {
                  result.add(input[i][j]);
              }
              j++;
              k--;
          }
  
          if (i &gt; row + 4 || j &gt; col + 4)
              break;
  
          k = steps;
  
          while (k &gt; 0) {
              if (inBounds(i, j, n)) {
                  result.add(input[i][j]);
              }
              i++;
              k--;
          }
  
          if (i &gt; row + 4 || j &gt; col + 4)
              break;
  
          steps++;
  
          k = steps;
  
          while (k &gt; 0) {
              if (inBounds(i, j, n)) {
                  result.add(input[i][j]);
              }
              j--;
              k--;
          }
  
          if (i &gt; row + 4 || j &gt; col + 4)
              break;
  
          k = steps;
  
          while (k &gt; 0) {
              if (inBounds(i, j, n)) {
                  result.add(input[i][j]);
              }
              i--;
              k--;
          }
          steps++;
  
          if (i &gt; row + 4 || j &gt; col + 4)
              break;
  
      }
      return result;
  }
  
  boolean inBounds(int i, int j, int n) {
      return (i &gt;= 0 &amp;&amp; i &lt;= n - 1 &amp;&amp; j &gt;= 0 &amp;&amp; j &lt;= n - 1);
  }
  </code></pre>