Squarespace | OA | Senior SWE

Anonymous User
1036
Jun 28, 2022
Jun 28, 2022

Implement a notifications feed based on the following stub
The notification feed only shows the most recent notification.
The user can dismiss it (pop) to see the next one.
The notification engine can add new ones on top or move an old notification back to the top.
It can also remove any notification in the feed.
Optimize for runtime complexity O(1) for all operations except evict(Duration timeInFeed)

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

/**
 * This is a notifications feed.
 * The feed maintains a "Last-In-First-Out" (LIFO) retrieve policy.
 */
class NotificationFeed {

	/**
	* Adds an element to the feed.
	* An element can exist only once in the feed.
	* Each call to add behaves as if the element was added for the first time.
	*/
	 void add(Notification element) {
	 
	 }
	 
	/**
	* @return true if the element is in the feed, false otherwise
	*/

	boolean contains(Notification element) {     

	}

	/**
	* Removes the given element from the feed.
	*/
  
	void remove(Notification element) {
		
	}

	/**
	* Retrieves and removes the most recently added element, following the LIFO policy.
	*
	* @return the most recently added element or null if the feed is empty.
	*/
	//O(1)
	Notification pop() {         
	}

	/**
	* @return The number of elements in the feed
	*/
	int size() {
		// TODO implement
		return 0;
	}
	
	// evict(Duration.ofHours(1)) would remove any elements that have been in the feed for >= 1 hour
	public void evict(Duration timeInFeed) {
		
	}
}

class Notification {
	private final String id;
   
	Notification(String id) {
		this.id = id;        
	}
	
	String getId() {
		return id;
	}
}


public class Solution {
	public static void main(String[] argv) {
		
	}
}
Comments (2)