Agoda Bangkok Thailand Interview Java

Agoda Bangkok Thailand Interview Java

race condition
SOLID design principal
Memory Increasing with time with CPU constant, how to fix on production environment ?
Cap Theorem
Composition vs association
Should misrocservices be async ?

Design Distributed Scheduler ?

Given following SQL table with 500 million entries

user_id, job_id(primary key), frequency, http_url, is_enabled

http_url: is http url that returns 200 OK response on GET request

user_id: Is user identifier, one user can have multiple records in the table

output should be as follows :

job_id : latency, status code, paylpoad size

Solution : Distribute load based on range of job-id (range based partition) along with caching along with writing back the result as a master-slave replica.

Given that we are getting a stream of parent child relationship, where first element is parent and secind is child. We need to find the entries with 0 and 2 parents.

1 3
\ / \
2 5
/ / \
4 6 7
\ /
8

(1,2)
(3,2)
(3,5)
(2,4)
(5,6)
(5,7)
(4,8)

Entries with 0 parent – 1,3
Entries with 2 parents – 2,8

class Solution {
public static void insert(int x , int y,HashMap> hm)
{
if(hm.containsKey(y))
{
List temp = hm.get(y);
temp.add(x);
hm.put(y,temp);
}
else
{
List p= new ArrayList<>();
p.add(y);
hm.put(y,p);
}

if(!hm.containsKey(x)){ List p= new ArrayList<>(); hm.put(x,p); } }

public static void main(String[] args) {

HashMap> hm = new HashMap<>();

  // Enter entries in hm 
    // for every element 
     insert(1,2,hm);
insert(3,2,hm);
insert(3,5,hm);
insert(5,6,hm);
insert(5,7,hm);
insert(4,8,hm);

// (1,2)
// (3,2)
// (3,5)
// (2,4)
// (5,6)
// (5,7)
// (4,8)

System.out.println(“2 parents :”);

for(Integer i : hm.keySet()) {

if(hm.get(i).size() ==2)

System.out.println(i);

}

System.out.println(“0 parents :”);

for(Integer i : hm.keySet()) {

if(hm.get(i).size() ==0)

System.out.println(i);

// add to list with 2 parents

//if(hm.get(i).size() ==0)

// add to list with 0 parents }

}
}

C++ C C# Health concepts Leetcode Programming Data Streucture