We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
HackerRank City
HackerRank City
Sort by
recency
|
34 Discussions
|
Please Login in order to post a comment
O(n)
My O(n) solution:
collect following 4 parameters at each of n steps:
Initially (before first step) there is 1 node, and other values are zeros. Calculate values for current step from previous step values in O(1).
here is my solution in java, javascript, python, C, C++, Csharp HackerRank City Problem Solution
Here is the solution of HackerRank City Click Here
here is a dp solution with
O(N)
time complexity. Space complexity isO(1)
as it uses 8long
variables for any problem size ofN
.To not obscure the calcuation in the codes, all values that was supposed to be a
long
type is replaced by aModValueT
type. All% 1000000007
operation is then done inside theModValueT
.