Java | Easy | Using Double Ended Queue
\nclass RLEIterator {\n    ArrayDeque<Integer> q;\n    public RLEIterator(int[] encoding) {\n        q = new ArrayDeque<>();\n        for(int  val : encoding){\
```\nclass RLEIterator {\n    ArrayDeque<Integer> q;\n    public RLEIterator(int[] encoding) {\n        q = new ArrayDeque<>();\n        for(int  val : encoding){\n           q.addLast(val);\n        }\n    }\n    \n    public int next(int n) {\n      int le = -1;\n      while(n > 0 && q.size() >= 2){\n         int freq = q.removeFirst();\n         int num  = q.removeFirst();\n         if(freq >= n){\n            freq = freq - n;\n            \n          if(freq !=0 ){ \n            q.addFirst(num);\n            q.addFirst(freq);\n          }\n           return num;\n         }\n         else{\n           n = n - freq;\n        }\n        le = num;\n      }\n      if(n != 0) return -1;\n      \n      return le;\n    }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator obj = new RLEIterator(encoding);\n * int param_1 = obj.next(n);\n */\n```
[]