Easy Solution using QUEUE | C++
IntuitionThe idea is inspired by pairwise reduction, where at each step, two adjacent numbers are summed, and only the last digit (% 10) is considered.The proce
# Intuition
The idea is inspired by pairwise reduction, where at each step, two adjacent numbers are summed, and only the last digit (% 10) is considered.
The process continues until only two digits remain.
Finally, we compare the last two digits to determine if they are the same.
# Approach
Initialize a queue: Convert the input string s into a queue, storing its digits as integers.
Iterative Reduction:
While the queue has more than two elements:
Process the queue by summing adjacent elements, taking (first + second) % 10, and pushing it to the queue.
After processing all elements for that iteration, remove the last element from the queue (since it has already contributed to the summation).
Final Check:
After the loop, two elements remain in the queue.
If both elements are equal, return true; otherwise, return false.
# Complexity
- Time complexity:
This forms a series O(n + (n-1) + (n-2) + ... + 3) ≈ O(n²).
- Space complexity:
 The space complexity is O(n).
# Code
```cpp []
class Solution {
public:
    bool hasSameDigits(string s) {
        queue<int>st;
        for(int i=0;i<s.size();i++){
            st.push(s[i]-'0');
        }
        while(st.size()>2){
            int n=st.size();
            for(int i=0;i<n-1;i++){
            int first=st.front();
            st.pop();
            int second=st.front();
                st.push((first+second)%10);
            }
            st.pop(); 
        }
 int first=st.front();
            st.pop();
            int second=st.front();
            if(first==second) return true;
            return false;
    }
};
```
['Queue', 'C++']