PE2 (AY21/22)
Last updated
Last updated
Questions:
Official Answers:
This is a give-away question.
This is also a give away question, the main part is to think about the logic of is_larger()
clearly. My solution is below:
This question utilises the idea of building a frequency table/counting sort
Okay, I think this question is not that interesting, that's because the most important information in this question is not given clearly. That is 148 is the largest number that is a "cycle", so this means our largest cycle number is 148, which should be the largest index of our frequency table.
This problem is a variation of binary search.
The tricky point is to deal with the edge/boundary cases. The change point is that:
If mid is '#', we change our search range to (mid+1, end)
If mid is '.' we change our search range to (start, mid)
And our base case is when our search range is 1 (start==end
), we return start
, which is either the first position of .
or the position of the edge.
In this problem, the end
is not inclusive!
The strlen()
from C standard lib <string.h>
will return the number of characters in a string (excluding the terminating '\0'
).
This question is very likely to . The idea are very similar, the only thing that serves as a game changer is that you need an array visited
to mark whether a person has appeared in your path or not.
Whenever you see the Time complexity is , try to think of binary search.