both problems here: https://leetcode.com/discuss/interview-question/5497148/snowflake-intern-oa-questions
Can anyone please give hints for the 2nd problem, I have no clue how to approach it. Thank you
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
both problems here: https://leetcode.com/discuss/interview-question/5497148/snowflake-intern-oa-questions
Can anyone please give hints for the 2nd problem, I have no clue how to approach it. Thank you
Название |
---|
Denote '0' for the zero-adjacent processor, '1' for the one-adjacent processor, and '2' for the two-adjacent processor. Then, each valid sequence of deployments results in a unique string of '0', '1', 'and '2'. We'll call such a string valid.
In a valid string, ignoring '1's, we see that '0' and '2' must "alternate", starting and ending with '0' (e.g. if you remove '1's in a valid string, then the sequence must look something like "020202020"). Furthermore, it is easy to see that any string that satisfies this corresponds to a valid sequence of deployments.
Then, setting up a DP recurrence should be relatively straightforward with this observation.
Think about applying all the possibilities of the types of adjacent and how for applying one type of operation on i, it affects on i+1.
It can be solved using dp
For example If want no adjacent on i, then it is bound for i+1 to be either one adjacent or two adjacent.
Or if I want i to be two adjacent then it bound for i+1 to be no adjacent or one adjacent
Thank you