2526. Find Consecutive Integers from a Data Stream Medium

@problem@discussion
#Hash Table#Design#Queue#Counting#Data Stream



1/**
2 * [2526] Find Consecutive Integers from a Data Stream
3 *
4 * For a stream of integers, implement a data structure that checks if the last k integers parsed in the stream are equal to value.
5 * Implement the DataStream class:
6 * 
7 * 	DataStream(int value, int k) Initializes the object with an empty integer stream and the two integers value and k.
8 * 	boolean consec(int num) Adds num to the stream of integers. Returns true if the last k integers are equal to value, and false otherwise. If there are less than k integers, the condition does not hold true, so returns false.
9 * 
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input
14 * ["DataStream", "consec", "consec", "consec", "consec"]
15 * [[4, 3], [4], [4], [4], [3]]
16 * Output
17 * [null, false, false, true, false]
18 * Explanation
19 * DataStream dataStream = new DataStream(4, 3); //value = 4, k = 3 
20 * dataStream.consec(4); // Only 1 integer is parsed, so returns False. 
21 * dataStream.consec(4); // Only 2 integers are parsed.
22 *                       // Since 2 is less than k, returns False. 
23 * dataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True. 
24 * dataStream.consec(3); // The last k integers parsed in the stream are [4,4,3].
25 *                       // Since 3 is not equal to value, it returns False.
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	1 <= value, num <= 10^9
31 * 	1 <= k <= 10^5
32 * 	At most 10^5 calls will be made to consec.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/find-consecutive-integers-from-a-data-stream/
38// discuss: https://leetcode.com/problems/find-consecutive-integers-from-a-data-stream/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42struct DataStream {
43        false
44    }
45
46
47/** 
48 * `&self` means the method takes an immutable reference.
49 * If you need a mutable reference, change it to `&mut self` instead.
50 */
51impl DataStream {
52
53    fn new(value: i32, k: i32) -> Self {
54        
55    }
56    
57    fn consec(&self, num: i32) -> bool {
58        
59    }
60}
61
62/**
63 * Your DataStream object will be instantiated and called as such:
64 * let obj = DataStream::new(value, k);
65 * let ret_1: bool = obj.consec(num);
66 */
67
68// submission codes end
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn test_2526() {
76    }
77}
78


Back
© 2025 bowen.ge All Rights Reserved.