VMware | MST4 | Sennior Lead Software Engineer | All Rounds (Team 2)

Round 1:

Question 1:

How to handle long running task asynchrnously and get it completed. How will you design such system for this purpose. Tell me the perfect approach.
//IFor example: Install and configure VMWare service. Here what if my one container fails and other container want to pick up the task from the point where it was left incomplete. 

Solution: 

I suggested her to divide the task as below:
1) Divide
2) Fetch api __package__
3) Install each package /execution
4) Verification /test
5) Deployment on client machine
6) Vulnerability chk

Main agreed Solution:
Save request and response in DB
Note: server cache solution will fail as we are talking about multiple containers - which run on different client machines not servers.

Question 2:

  • What is single object responsibility
  • Implement your own singleton class with threadsafe implementation
1. public class Singlton {
2. 
3.   public static final singleton = null;
4.   
5.   Singlton() {}
6.   
7.   public static Singlton getInstance() {
8.     
9.     if(sington == null) {
10.       //object level locking
11.       synchronized(this) {
12.         if(singlton == null) {
13.       		singleton = new Singlton();
14.         }
15.       }
16.     }
17.     else singlton;
18.   }
19. }
 

- Difference between class level lock and object level lock
- Line 11, what does synchronized block does here
- what if multiple thread reaches at line 9 and try to access the same, what will happen to both the threads
  (Ans: Add null check at line 12)
- What is lazy initialization
- what if you write sunchronized keyword at getInstance method then having synchronized block (And: Reduces performance as lock is done at method level)

Q3: Implement your own hashmap

//Functions: Buckets - Entry<Key, value>
//get
//put

Answer:
public class Map<K, V> {
   private Entry<k, V>[] buckets; 
   public static final int CAPACITY = 16;
  
   Map(Entry<k,v>[] buckets) {
     this.buckets = buckets;
   }
  
  Map() {
    buckets = new Entry[CAPACITY]; 
  }
  
  public get() {
    
  }
  
  public put(K key, V value) {
    Entry<K, V> e = new Entry<K, V>()key, value)
    if(key == null) {
       bucket[0] == obj; 
    }
     //calculate hashcode
     //buckNum = hashcode % capacity
     //bucket[] = Entry;
     int bucketNum = getHash() % CAPACITY;
     if(bucket[bucketNum] == null) {
        bucket[bucketNum] = e;
     } else if( bucket[bucketNum] != null) {
         if e.key.euqlas(buckets[bucketNum].getKey()) {
            bucket[bucketNum] = e;
         } else {
           // Create LinkedList
           // create Node
         } 
     }
  }
  
  getHash(K key) {
    //Object class hashcode()
     return hashCode();
  }
}

Questions on this map implementation:

  • why map uses Integer and not int
    Ans: Because Integer is wrapper class and inherited from Object class, Map uses Object class as base class and need to use Equals and hashCode for operations. Hence it used Wrapper than primitives

Round 2:

  • What is & diff between @Bean and @Component
  • What is & diff between @Service @Controller and @Component

Programing Question 1:

Write a program to Return number of words in a sentense.
Criteria:

  • Words can end with :,.
  • Each words seperated by space
  • Word can only have a-z or A-Z

Programing Question 2:

Write a program to shift all 0's to left and 1's to right.
Input: Arr = [0,1,0,0,1,1,0]
Output: [0,0,0,1,1,1]

public class ShiftAllZeroLeft {
    public static void main(String[] args) {
        int[] arr = {1,1,1,0,0,1,0,0,1};
        int[] outputArr = shiftElem(arr);
        for (int i: outputArr) {
            System.out.println(i);
        }
    }

    static int[] shiftElem(int[] arr) {
        int count=0;
        for (int i: arr) {
            if(i != 1) {
                arr[count++] = i;
            }
        }
        System.out.print("count" + count);
        for(int i= count; i<arr.length; i++) {
            arr[i] = 1;
        }
        return arr;
    }
}

**Programing Questions 3: **

Find number of missing duplicate element :
Input: a1 = {1,2,3,4};
a2 = {2,3,4,8,10};
Output: 3

import java.util.*;
import java.lang.*;

public class Assign {
    public static int findMissingDuplicate(int[] a1, int[] a2) {
        int count =0 ;
        Set<Integer> set = new HashSet<>();
        
        if( a1 == null || a2 == null) {
            return 0;
        } else {
            for (int i : a1) {
                //System.out.println("i"+i+" "+set.add(i));
                if(!set.contains(i))
                    set.add(i);
                else 
                    set.remove(i); 
            }
            for (int i : a2) {
                //System.out.println("i"+i+" "+set.add(i));
                if(!set.contains(i))
                    set.add(i);
                else 
                    set.remove(i); 
            }
            count = set.size();       
        }
        return count;
    }
    
    public static void main(String[] args) {
        int[] a1 = {1,2,3,4};
        int[] a2 = {2,3,4,8,10};
        System.out.println(findMissing(a1, a2));
    }
}

Round 3:

Question 1:

Given Integer Array in sorted order (asc) => {1, 3, 4, 5, 6, 8, 9} =>
Ask is to find an integer => find(5) => 3 ,
find (2) => -1

public class Find {
        public static int findElem(int[] arr, int elem) {
        int s = 0, e = (arr.length-1);
        while(s<=e) {
            int mid = s+(e - s)/2;
            
            if(elem == arr[mid]){
                return mid;
            }
            
            if(elem <= arr[mid]) {
                //left sub array
                if (elem >= arr[s] && elem < arr[mid]) {
                    e = mid-1;
                } else 
                    s = mid +1;
                    
            } else{
                //Right subarray
                if(elem > arr[mid] && elem <= arr[e]) {
                    s = mid +1;
                } else 
                    e = mid -1;
            }
        }
        return -1;  
    }
    
    public static void main(String[] args) {
        int[] arr = {1, 3, 4, 5, 6, 8, 9};
        System.out.println(findElem(arr, 2));

Question 2:
arr1 = {2, 5, 8, 0, 0, 0, 0}, arr2 = {1, 3, 4, 7} , sorted (asc) , merge 2 array => return/merged array (sorted array having all the elements in sorted order)

public static int[] mergeArray(int[] a1, int[] a2) {
	if(a1 == null) 
		return a2;
	if (a2 == null)
		return a1;

	int i = a1.length-1;
	int j = a2.length-1;
	int k = (i+j) - 1;

	int[] a3 = new int[i+j];      
	while(j>-1) {
		if(i<0) {
		   a3[k--] = a2[j--];
		} else {
			if(a1[i] > a2[j]) {
				a3[k--] = a1[i--];
			} else
			   a3[k--] = a2[j--];
		}
	}
	return a3; 
}

public static void main(String[] args) {
	int[] a1 = {2, 5, 8};
	int[] a2 = {1, 3, 4, 7};

	int[] a3 = mergeArray(a1, a2);
	for (int i : a3) {
		System.out.println(i);
	}  

Question 3:

Write a program to compare two objects. For example user. How can I have users sorted by name. which is the best data structure to be used. Implement all methods.

Solutions:
Either use comparable method or override hashCode and equals methods

Implementation:
```

  
	 public static void main() {
	  /*TreeSet<User> tm= new TreeSet<User>(new MyCompare());
        tm.add(new User(1, "Ankita"));
        tm.add(new User(2, "Sushil")); */
    }
	
    
    /*class MyCompare implements Comparator<User>{
        public int compare(User u1, User u2) {
            return u1.getUserName().compareTo(u2.getUserName());
        }
    }*/
}

class User {
    int id;
    String userName;
}
    
/*
@Override
int hashCode(Object o) {
    
    if (u == null)
       return 0;
    else {
        int primt = 31;
        int uniq = u.userName + u.id;
        int hash = prime + uniq;
        //algo to unique hashing value cal
        
        return hash;
    }
}

@Override
boolean equals(Object o) {
    if (o == null) 
      return false;
    else {
          if (getClass() == o.getClass())
             return true;
      }
}*/

Round 4:

I was asked to write pseudo code for the below programming question. Rest all were project specific question which were asked by other interviewers as well, as mentioned below :

  • Why jenkins over gitlab
  • What improvements can you think of to improve existing functionality in my project which we spoke about(for example feature flipping). Improvement I suggested was to switch feature flipping from code config to admin UI
  • What CI/CD model you use.
  • What you product does
  • How many microservices you have and overall architecture of the project.

Programing 1:

Write a program to find the node at which the intersection of two singly linked lists exist
https://leetcode.com/problems/intersection-of-two-linked-lists/


Round 5: With Senior manager

  • My current product, architeture of the product
  • Functinality of the product
  • Company culture
  • Passion
  • What should we do to keep you with VMware in future
  • My past job details and location
  • Pay details
  • Roles and responsibility discussion

Round 6:

-Introduction as usual

  • Past experience
  • Current product
  • Do you use container to deploy your artifacts
  • About aws and cloud
  • Current functionality

Design an api to whitelist IP address tenant specific. IP address should be configurable(add/update/select) from admin screen.

  • How to verify if input ip is matching with those in DB in more efficient way.
    Ans: put all DB table data in map and apply for loop over input list and do map.get(l);
  • how to verify say if I belong to a tenant "M&G" and want to enlist iP address of MG, how to incominng IP is is from that tenant itself. (Ans: Verify in user service if person belongs to that tenant, if yes fetch and pass on the property)
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

@Component
public class AuthenticationProvider implements AuthenticationProvider {

   Set<String> authIpList = new HashSet<String>(); 
   
   public AuthenticationProvider() {
       authIpList.add("10.35.12.23");
       authIpList.add("10.35.12.25");
   }
   
   public Authentication authentic(Authentication auth) {
       
       List<String> tenants = Env.get(kea.multi-tenancy);
       http.authorize()
       .antMatcher("/mg").hasIpAddr();
       //contains code to whitelist IP
   }
}

@RestController
@RequestMapping("\api\Security")
public class IpController {
    
    private final IpService ipService;
    
    @PostRequest("\ip\{ip_list}\{tenant}")
    public ResponseEntity<String> addIp(PathVariable(value="ip_list") List<String> ipList, @PathVariable(value = "userName") String tenant) {
        Set<String> set = new HashSet<>();
        for (String ip : ipList) {
            set.add(ip);
        } 
        
        //Store in DB
        String resCode = ipService.addIpList(set);
    }
    
    @PostRequest("\ip\{ip_list}\{tenant}")
    public ResponseEntity<String> updateIp(PathVariable(value="ip_list") List<String> ipList, @PathVariable(value = "userName") String tenant) {
        
        //Store in DB
        String resCode = ipService.addIpList(set);
    }
}

@Service
public class IpService extends RestService{
    
    public String addIpList(Set<String ipList> ipList) {
        //call repo to add
    }
    
    public String updateIp(List<String> ip) {
        //call repo to update
    }
    
    public List<String> fetchAll(String tenantId) {
        //call fetch
    }

}

@Repository
public class IpRepo implement JPARepository{
    List<String> selectList(string tenantId);
}

@Entity
public class IpAddr {
    
    @IDProperty
    @GeneratedValue()
    int id;
    
    @Column("ipAddr")
    String ipAddr;
    
    @Column("tenantid")
    int tenantId;
    
    /*Create table IpAdd {
        //int id;
        //varchar2 ipAddr;
        //int tenantId
    }
    Database:
    1  10.2.32.45 MG
    */
}

//Configuration file for multi tenancy
application.yml {
    env: dev, stage, prod
    kea:
        multi-tenancy: axa, mg, aviva, jp, ss
}
}
Comments (2)