Can this problem : Bounded distinct be solvable using two pointer ? If yes what is the logic ? I implemented it with two pointer but code become very much complex . My code . Getting WA for this code .
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Can this problem : Bounded distinct be solvable using two pointer ? If yes what is the logic ? I implemented it with two pointer but code become very much complex . My code . Getting WA for this code .
Название |
---|
I think you're somewhat on the right track based on what I could understand from your code. Just try to make it a lot simpler. What are your two pointers? What should be the state at the end of each iteration?
The simplest idea I could think of is to find the largest valid subarray for each starting index. Left pointer would be the starting index and at each iteration we move the right pointer until we find a duplicate (or hit either the end of the array or maximum allowed interval length) and count the number of valid intervals starting from this index. Sample implementation.
I wasted most of the time in contest for a small mistake in this problem. The final answer can range upto 1e10, you should use long long for the answer instead of int. :P