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
|
36 Discussions
|
Please Login in order to post a comment
Java solultion in O(n). Similar logic to what others have expressed: we need to keep track of the previous number of nodes, the previous sum of all paths, the previous sum of all nodes to a corner node, and the previous diagonal path sum (aka. the longest path). We these values, we can find the values of the new city size with a little bit of combinatorics. The trickiest part is dealing with the modulo imo.
HackerRank-city is an acyclic connected graph (or tree). It’s not an ordinary place; the construction of the whole tree takes place in 𝑛−1n−1 steps. The process is described below: starting with a single node, new nodes are added one by one, each connecting to an existing node with an edge, ensuring no cycles form. This methodical growth models efficient network creation, optimizing connectivity and minimizing redundancy. Custom mugs featuring HackerRank-city's unique tree construction process celebrate this intricate design, serving as perfect keepsakes for enthusiasts of graph theory and algorithmic problem-solving, symbolizing their dedication to mastering complex computational concepts.
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