Current Employment :
Position: Software Engineer (3 Years)
Location: Mumbai, India
Revolut :
Position : Senior Java Backend Engineer - India RemotelyInterview Process :
Technical Round 1 ( 45 Mins )
1. Create a LoadBalancer class that has a method to register backend instances
Each backend instance address should be unique, it should not be possible to register the same address two times
Load balancer should accept up to 10 backend instances
The code should be production ready
The Loadbalancer will be released as a library
2. Develop an algorithm that, when invoking the Load Balancer's get() method multiple times,should return one backend-instance choosing
between the registered ones randomly.
Result : Rejected.My Approach :
public class BackendInstance {
public String address;
BackendInstance(String input) {
this.address = input;
}
}===============================================
public class LoadBalancer {
Map<String, BackendInstance> db = new HashMap<>(10);
public boolean register(BackendInstance input) {
boolean registered = false;
if(db.size() < 10) {
if(db.containsKey(input.address)) {
System.out.println("Address Already exist....");
} else {
db.put(input.address, input);
System.out.println("New Instance Registered....");
registered = true;
}
} else {
System.out.println("Overload");
}
return registered;
}
public BackendInstance get() {
String[] dbList = (String[]) db.keySet().toArray();
Random random = new Random();
int randomNumber = random.nextInt(10);
return db.get(dbList[randomNumber]);
}
}=====================================
public class LoadBalancerTest {
@Test
void testDuplicate() {
LoadBalancer loadBalancer = new LoadBalancer();
BackendInstance backendInstance = new BackendInstance("hastimal");
Assertions.assertTrue(loadBalancer.register(backendInstance));
Assertions.assertFalse(loadBalancer.register(backendInstance));
}
@Test
void testMaxSize() {
LoadBalancer loadBalancer = new LoadBalancer();
List<String> user = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
List<BackendInstance> userList = user.stream().map(BackendInstance::new).collect(Collectors.toList());
for(int i=0; i < user.size(); i++) {
if(i < 10) {
Assertions.assertTrue(loadBalancer.register(userList.get(i)));
} else {
Assertions.assertFalse(loadBalancer.register(userList.get(i)));
}
}
}}
Experience :
My Code is not upto the mark there are many flaws.
Your Expected to code the above requirements and test the same using Junit.
I completed the coding for both but only testCode for 1st one due to time constrait not able to write test for secondAdvice :
Keep SOLID priciple in mind during coding. Interviewer Emphasis more on your approach/Understanding then your code. Summary :
It was great experience. I ll definetly apply again.