C++ Solution that Google interviewers will fail you
\nclass RLEIterator\n{\npublic:\n    RLEIterator(vector<int>& encoding) : m_cur_pos(0)\n    {\n        const int SIZE = encoding.size();\n        \n        int 
```\nclass RLEIterator\n{\npublic:\n    RLEIterator(vector<int>& encoding) : m_cur_pos(0)\n    {\n        const int SIZE = encoding.size();\n        \n        int target_value = encoding[1];\n        \n        for(int index = 0; \n            index < (SIZE -1);\n            index += 2)\n        {\n            const int cur_frequency = encoding[index];\n            \n            if(cur_frequency == 0)\n            {\n                continue;\n            }\n            \n            const int cur_value = encoding[index +1];\n            \n            if(cur_value != target_value)\n            {\n                target_value = cur_value;\n                \n                ++m_cur_pos;\n            }\n            \n            m_position_KEY_value_frequency_VALUE_map[m_cur_pos].first   = cur_value;\n            m_position_KEY_value_frequency_VALUE_map[m_cur_pos].second += cur_frequency;\n        }\n        \n        // RESET\n        m_cur_pos = 0;\n    }\n    \n    int next(int num_values_to_be_removed) \n    {\n        int target_value = m_position_KEY_value_frequency_VALUE_map[m_cur_pos].first;\n        \n        m_position_KEY_value_frequency_VALUE_map[m_cur_pos].second -= num_values_to_be_removed;\n     \n        int remainder_frequency = 0;\n        \n        while(m_cur_pos < m_position_KEY_value_frequency_VALUE_map.size() &&\n              m_position_KEY_value_frequency_VALUE_map[m_cur_pos].second < 0)\n        {\n            remainder_frequency = m_position_KEY_value_frequency_VALUE_map[m_cur_pos].second;\n            \n            ++m_cur_pos;\n            \n            if(m_position_KEY_value_frequency_VALUE_map.count(m_cur_pos))\n            {\n                target_value = m_position_KEY_value_frequency_VALUE_map[m_cur_pos].first;\n            \n                m_position_KEY_value_frequency_VALUE_map[m_cur_pos].second += remainder_frequency;    \n            }\n            \n            else\n            {\n                return -1;\n            }\n        }\n        \n        return target_value;\n    }\n    \nprivate:\n    \n    int m_cur_pos;\n            \n    // Key   = position\n    // Value = pair<cur_value, cur_frequency>\n    unordered_map<int, pair<int, int>> m_position_KEY_value_frequency_VALUE_map;\n};\n\n\n```
[]