I have been trying hard but could only solve question 2 completely. I would be grateful if you could give your insights and ways to solve the rest of the question. Link to any tutorial for the required algorithms is equally appreciated.
In the 3rd Question, Basic recursion could do the job. For reference search for “N Queen Problem”, go for the algo which is solved for the total number of possible positions of queens.
Basic insights:
Make a isValid() to check the scope of adjacent indexes you will be visiting.
In each recursive call pass the current length of password obtained.
Base case will be when CurrLength == GivenLength , Increment the count in this If-statement and include return statement.
To solve the q3 , we need to find something interesting here , i.e
The number of passwords starting with 2 and having length k is equal to number of passwords starting with 4 and having length k is equal to the number of passwords starting with 6 and having length k is equal to the number of passwords starting with 8 and having length k
The number of passwords starting with 1 and having length k is equal to number of passwords starting with 3 and having length k is equal to the number of passwords starting with 7 and having length k is equal to the number of passwords starting with 9 and having length k
Having this , you can continue to get the answer
Hope you understood
How should we approach ZIO problems? Is there any general rule or method to come up with the appropriate strategy to solve the question in the given time? What topics or algorithms should be focused on?
Yeah not exactly but making the trie is the first step. Then you can define states for each node. Btw I leave out the operations for printing the word as it’s easier to add these ops in the end.
Dp(node, 0) = min number of moves to traverse this subtree and come back to this node.
Dp(node, 1) = min number of moves to traverse this subtree completely.
Try to get the transitions. Also this isn’t the normal dfs traversal. Rather it’s moving along the path. And then retracing back - like that.