Dos retos de entrevista de trabajo

Meses atrás participé en un proceso de selección en una empresa donde estaban solicitando desarrolladores Java. Ya no recuerdo el nombre de la empresa pero era de capital argentino. Como parte de la entrevista de trabajo, la empresa dejaba a los candidatos resolver dos retos que en esta entrega les comparto. El texto de los problemas es tal cual venían. No les cambié ni una solo coma.

Al final no me quedé en esa empresa, contrataron a alguien más, sin embargo, si llegué bastante lejos dentro del proceso de selección. No pude resolver estos problemas de una manera adecuada. Todavía me faltaba mucha experiencia, sobre todo en lo que tiene que ver con el dominio del IDE, el sistema de control de versiones, logging y pruebas unitarias. Casi nada ¿verdad? De hecho hasta se me olvidó preguntar si podía usar framework. Esto habría sido muy útil para resolver el problema 1.

Por el momento no tengo las soluciones subidas al repositorio así que se los debo para alguna actualización de este post. De hecho perdí la solución del problema 1 y todavía conservo por ahí la del problema 2. A ambas soluciones les falta mucho trabajo.

Como comentario final, yo siento que estos problemas tienen nivel. Creo que como se estaban evaluando a candidatos para un puesto de nivel senior entonces se requerían problemas para evaluar esas habilidades. Aunque debo decir que esto no es el estándar. En la gran mayoría de las entrevistas de trabajo los problemas que se tiene que resolver, uno o dos, son del estilo de los de Hacker Rank.

Problema entrevista de trabajo 1

A third party finance service ‘X’ provides currency conversion rates every 5min. 
For the purpose of this problem you can assume that the service ‘X’ places the files in the directory: "/tmp/exchange”. 
This directory contains two types of files:
Build file
Data files  

buildID.txt
This file contains the build number corresponding to the data and the latest data file name to be read. 
A sample build file might look something like this -

Contents of buildID.txt 
{
   “buildID”:  “1234”,
   “FileName”: “20201010-0000.txt”,
   “Version”:  “v1"
} 


Data Files
These are the files which contain the actual currency conversion data. 
The latest data file will pointed to by the “FileName” field in buildID.txt. 
A sample data file will look something like this -

20201010-0000.txt
{
   “CAD_USD”: 0.98,
   “FR_USD”: 0.9,
….

}

The finance service’s producer will create new conversions every 5 mins. 
This means replacing the buildID.txt with the new buildID and a new location of the data file appended with a different timestamp: e.g "20201010-0005.txt”.  
After 5min directory will contain following files:
buildID.txt
20201010-0000.txt
20201010-0005.txt

With contents of buildID.txt being:
{
   “buildID”:  “1235”,
   “FileName”: “20201010-0005.txt”,
   “Version”:  “v1"
} 


You need to write an application that will read this data and keep the conversions in memory. 
Your application needs continuously poll "/tmp/exchange" directory for the buildID file every 1min and read the latest contents of the buildID and the corresponding data file. 
You need to process the currency data and store it in a map in memory for quick access. 
The map would look something like this - 
{
	“CAD_USD”: 0.98,
	“FR_USD”: 0.9,
}
If during a poll, the buildID is same as what has already been read, the application should not replace contents of the currency conversions in memory.

Problema 2

XY land is a huge 2D plane with an X axis and a Y axis. The range of X axis is 0 to 109 and the range of
Y axis is also 0 to 109. In XY land houses are built only in integer co-ordinates and there is exactly one house
in each integer co-ordinate.
A detergent selling company is launching a new detergent. They want to advertise their product as much as possible. 
They selected n persons for this task. Each person is given a rectangular region. 
The person will advertise the product to all the houses that lie in the region. 
Each rectangular region is identified by 4 integers x1, y1, x2 and y2. 
That means this person will advertise in all the houses whose x co-ordinate is between x1 and x2 (inclusive) 
and y co-ordinate is between y1 and y2 (inclusive).
After a while company realized that some houses are being advertised by more than one person. 
So, they want to find the number of houses that are advertised by at least k persons. Your goal is to find this answer.
You are given n, k and list of 4 integers x1, y1, x2, y2 (0 ≤ x1, y1, x2, y2 ≤ 109, x1 < x2, y1 < y2) denoting 
a rectangular region for a person and n such numbers for each salesman

Example

Case 1

Input
n=2, k=1, [[(0, 0), (4, 4)], [(1, 1), (2, 5)]]

Output
27
----------------------
Case 2

Input
n=2, k=2, [[(0, 0), (4, 4)], [(1, 1), (2, 5)]]

Output
8

Assume the input is always going to be valid. Feel free to use any data structures convenient for your input. Above cases are just 
to explain the problem, please test the problem with your test cases and provide the corresponding unit tests. 
We need an optimized working solution. Please provide the time and space complexity of your approach.
Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *