title: Implement Queue using fixed size array
body: <p>I came across below interview question and I am working on it:</p>
  
  <blockquote>
    <p>Build a queue class with the enqueue and dequeue methods. The queue
    can store an <strong>UNLIMITED</strong> number of elements but you are limited to
    using arrays that can store up to 5 elements max..</p>
  </blockquote>
  
  <p>Here is what I was able to come up with. Is this the right way to do it in the interview or is there any better way we should implement in the interview?</p>
  
  <pre><code>class Solution {  
    private final List&lt;List&lt;Integer&gt;&gt; array;
  
    public Solution() {
      this.array = new ArrayList&lt;&gt;();
    }
  
    public void enqueue(int value) {
      if(array.isEmpty()) {
        List&lt;Integer&gt; arr = new ArrayList&lt;&gt;();
        arr.add(value);
        array.add(arr);
        return;
      }
      if(array.get(array.size() - 1).size() != 5) {
        array.get(array.size() - 1).add(value);   
        return;
      }
      List&lt;Integer&gt; arr = new ArrayList&lt;&gt;();
      arr.add(value);
      array.add(arr);
      return;
    }
  
    public int dequeue() {
      if(array.isEmpty()) {
        return -1; 
      }
      for(List&lt;Integer&gt; l : array) {
        for(int i=0; i&lt;l.size(); i++) {
          return l.remove(i); 
        }
      }
      return -1;
    }
  }
  </code></pre>