Recently gave the OA test on HackerEarth for SE Intern'22 (Jan - Jun)
There were total 3 questions in total to be solved in 2 hours.
Input a string str, integer target. Remove the characters having adjacent number of characters of length equivalent to target.
Input str: "aaabbcdd", target = 2
Output: "aaac"Check if the given array of integers is spirally sorted.
An array is called spirally sorted when arr[0] <= arr[n-1] <= arr[1] <= arr[n-2] <= arr[2]...
Input arr: [1,3,4,2]
Output: true
Input arr: [1,2,4,3]
Outpur: false
Input arr: [1,10,14,20,18,12,5]
Output: trueUse of reverse proxies (https://en.wikipedia.org/wiki/Reverse_proxy) is quite common in modern web architecture. This problem aims to give you an insight on how they are integrated into online services and a glimpse into their internal working.
You are given a set of reverse proxies. Each reverse proxy can be identified by its domain name. For example it can be www.xyz1.com, www.xyz2.com. Both represent different reverse proxies. Users always communicate with these domain names by making requests to them. Like: www.xyz1.com/users/all
Each reverse proxy is connected to some set of internal machines. Each Internal machine can be connected to multiple reverse proxies. When a request from a user hits any reverse proxy, it is forwarded to one of the connected machines in a round robin fashion (https://www.nginx.com/resources/glossary/round-robin-load balancing/).
Due to certain events a reverse proxy can face intermittent connectivity issues to a machine it is connected to. On detecting this, it must remove that machine from the available list of machines. And once the network issues resolved, it must add it back to the list of machines. The network health monitoring is done by a separate service and it informs these events to the reverse proxy by two special requests (explained in the section below).
These special requests should not be forwarded to any of the machines as it is meant only for the reverse proxy. It is guaranteed that only disconnected machines can come up and only up machines can get disconnected, Initially all the machines are up.
Another thing to note is that once a disconnected machine comes back up, it is added to the end of the list of connected machines for a reverse proxy. Therefore, during the reverse proxy's lifetime the order of connected machines can change as they disconnect and come back up.
Each machine has a log file maintained on the disk (memory is volatile !!). When the machine receives a request from the reverse proxy it appends that request to the end of this requests log file.
Your task is to first represent the infrastructure, i.e. the reverse proxies and the connected machines internally in your program and then process a list of requests (given in chronological order) which will hit your infrastructure sequentially.
After processing all the requests, print the requests log file of each machine to STDOUT. The logs of the first machine should be printed first followed by the next machine and so on, in the format defined in the 'OUTPUT FORMAT section.
INPUT FORMAT:
First line contains the number N (number of internal machines).
The next line contains N space separated IPs which represent the internal machines.
The next line contains R (number of reverse proxies), following it we define the R reverse proxies. A reverse proxy consists of the following fields.
<domain_name>
<M, the number of connected machines>
<M space separated IPS of machines it is connected to>Domain name is unique for each reverse proxy.
Once we have defined the complete infrastructure, the next line contains Q (the number of requests to process).
After that, Q lines follow each representing a request to the reverse proxy.
A request is defined like the following:
<domain_name><path>
<path> can be any valid URI.Now, as mentioned above there are some special requests to represent if a machine disconnects or comes back up. Those special requests looks like this:
<domain_name>/machine_down?ip=<machine ip>
<domain_name>/machine_up?ip=<machine_ip>On receiving this request, the reverse proxy associated with domain name should remove from it-self or add it back as mentioned in the problem statement above
Note: Consider all inputs data (domains names, Ps, requests, etc) to be strings, do not waste time in verification of the input IP address for instance
OUTPUT FORMAT:
Output should have the request logs from each of the machines. It should follow the following format:
<machine_ip>
<requests>Requests should follow the same format specified above.
CONSTRAINTS:
0 < N < 1000
0 <= R <1000
0 <= M <= N
0 <= Q <300000