How to solve this question with the help of dfs/bfs/dijktra(as mentioned in ahmed-aly.com).This particular question has not been discussed much and don't have good resources to know about it.
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
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 |
How to solve this question with the help of dfs/bfs/dijktra(as mentioned in ahmed-aly.com).This particular question has not been discussed much and don't have good resources to know about it.
Name |
---|
I managed to solve this : Code
The main idea is to do a BFS, with the nodes being the pair(mod value , sum of digits).
Dude what made you come up with bfs ? Can you add comments in your code l'il bit :)
I can tell you how my code works. The start node is when the number is empty (0) with sum of digs and mod value is 0. We are doing the BFS since we need to find the minimum positive integer(which can be seen as shortest distance in the integer tree). Now if our element has a mod value 0 and sum of digits as N , then this is indeed our number and this is the shortest (since we are doing BFS , the first occurrence is indeed the smallest). Else what we try to do is append a digit [0-9] and mark this as a new node in the tree.
In code , the first two functions are basic ones. The bfs is also the basic one. I am using "lwr" variable to see if the digit can be 0 or not. This is done just to avoid leading zeroes.
You can ask if you have any doubts related to any part of code.