---
# System prepended metadata

title: 2526. Find Consecutive Integers from a Data Stream
tags: [Leetcode, Medium]

---

# 2526. Find Consecutive Integers from a Data Stream
###### tags: `Leetcode` `Medium`
Link: https://leetcode.com/problems/find-consecutive-integers-from-a-data-stream/description/
## Code
```java=
class DataStream {
    int count = 0;
    int value;
    int k;

    public DataStream(int value, int k) {
        this.value = value;
        this.k = k;
        count = 0;  
    }
    
    public boolean consec(int num) {
        if(num==value) count++;
        else count = 0;
        return count>=k;
    }
}
```
Deque
``` java=
class DataStream {
    int count = 0;
    Deque<Integer> q;
    int value;
    int k;

    public DataStream(int value, int k) {
        this.value = value;
        this.k = k;
        count = 0;
        q = new ArrayDeque<>();    
    }
    
    public boolean consec(int num) {
        count += 1;
        if(num!=value) q.add(count);
        if(count<k) return false;
        else{
            if(!q.isEmpty() && q.getFirst()<=count-k) q.removeFirst();
            return q.size()==0;
        }
    }
}
```