Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,488 views
in Interview-Experiences by Expert (30,360 points) | 1,488 views

1 Answer

0 like 0 dislike
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.
by Expert (30,360 points)