LinkedIn phone interview | senior software engineer role | Sunnyvale | Oct 2021

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2021-10-15Added By Anonymous
Source: Link

Company: LinkedIn
Role: senior software engineer
Interview Stage: Phone Screen
Location: Sunnyvale
Year: 2021

Original Post Content:

1 hour round: panel of 2
1. https://leetcode.com/problems/can-place-flowers/
2. Standard cache problem :
- should be able to store the values in cache as per capacity.
- If the value is present in cache, then get(key) method should return the value from cache. else use the standard cache to get the key and also store that in cache.
- if the cache is full, then discard the value with lesser rank. getRank method will help to get the rank.
- build the system in a thread safe way

public class Data{
  long rank;
  K key;
  V value;
  public Data(long rank, K key, V value){
    this.rank = rank;
    this.key=key;
    this.value=value;
  }
}

public class StandardCache<K, V extends Rankable> {
 
  /**
   * Constructor with a data source (assumed to be slow) and a cache size
   * @param ds the persistent layer of the the cache
   * @param capacity the number of entries that the cache can hold
   */
  public StandardCache(DataSource<K, V> ds, int capacity) {
    // Your code here
  }

  /**
   * Gets some data. If possible, retrieves it from cache to be fast. If the data is not cached,
   * retrieves it from the data source. If the cache is full, attempt to cache the returned data,
   * evicting the V with lowest rank among the ones that it has available
   * If there is a tie, the cache may choose any V with lowest rank to evict.
   * @param key the key of the cache entry being queried
   * @return the Rankable value of the cache entry
   */
  public V get(K key) {
    // Your code here
    
  }
  
}
  
  
/*
 * For reference, relevant interfaces: Rankable and DataSource.
 */
 
public interface Rankable {
  /**
   * Returns the Rank of this object, using some algorithm and potentially
   * the internal state of the Rankable.
   */
  long getRank();
}

/*
 * Remember that this is slow, relatively speaking
 */
public interface DataSource<K, V extends Rankable> {
  V get (K key);
}
Comments