Q1. IPList
Given a log file, return IP address(es) which accesses the site most often.
e.g: "10.0.0.1 - log entry 1 11", "10.0.0.1 - log entry 2 213", "10.0.0.2 - log entry 1 11", "10.0.0.2 - log entry 2 213", "10.0.0.2 - log entry 133132"
Ans: 10.0.0.1
Approach: Split Ip address and store in HashMap, return key with max value.
Q2. Train Map Problem
Rail network - consists of number of the Station objects. Stations in the map are bi-directionally connected. Distance between any 2 stations is of same constant distance unit. This implies that shortest distance between any 2 stations depends only on number of stations in between.
Implement def shortestPath(self, fromStationName, toStationName) method to find shortest path between 2 stations.
Approach: Use BFS, keeping a track of predecessor paths. Maintain visited nodes to avoid cycle.