How to run this code in multiple threads? Why can parallelStream() be dangerous?
Java
/* The company provides a mass notification sending service for other businesses. A product owner has approached you with a task to create a notification filtering system considering user preferences. ## Definitions Notification: - notification id - notification type (EMAIL, SMS, PUSH) - recipient (user id) - message text Recipient may have preference settings: - allowed notification channels (list of types) - blocked senders (list of sender ids) Notification sending history: - list of notifications sent to the user ## Important User settings and notification history are provided by other system components. You need to design contracts to obtain this data. Storage implementation is not required. ## Task Write a notification filtering system that: - takes a list of notifications for filtering and a sender id as input - excludes notifications that do not match user preferences - implements duplicate message protection, including messages sent in the last 24 hours. Duplicates are considered messages with the same id addressed to the same user - returns a filtered list of notifications ready to be sent. Sending notifications is not part of your task - another team will handle sending the filtered list. Your task is only filtering. */ class NotificationFilter { UserSettingsService userSettingsService; NotificationHistoryService notificationHistoryService; public ??? filter(??? senderId, List<???> msgs) { // TODO implement } } interface UserSettingsService { // TODO any functions } interface NotificationHistoryService { // TODO any functions }
Have you had experience with RAG and vector search?
Tell us about a complex authorization task when transitioning from monolith to microservices.
What is MCP and how does it work?
/** * Find the person with the minimum age in a room with the maximum number of people * At the end of the solution method, call writeSolution(user, room) */
How to solve the problem with NFT 50ms at current RT 150ms + 350ms? Suggest an architectural solution.
-- There are tables with the following structure Employee id (PK) name salary dep_id(FK department.id) Department id (PK) name -- write a query that returns a list of all department names with the maximum salary in each department select d.name, MAX(e.salary) from Employee e join Department d on e.dep_id = d.id group by d.name
Have you worked with locks in databases? How did you acquire locks?
What are functional interfaces? Which ones do you know? What do they accept and what do they return?
How do you monitor that the system is working correctly? What metrics and monitoring do you use?
Can any object be added to a TreeMap as a key?
What does the reduce method do?
Why did you use Spring Web for API Gateway instead of ready-made proxy solutions like Nginx, Envoy?
How to implement rate limiting for an external API with RPS restrictions? How do virtual threads/coroutines differ from system threads?
The database is large, indexes are built, the plan has been reviewed — what else can be done for optimization?
How do LinkedList and HashMap differ? How does LinkedHashMap differ from HashMap?
Have you ever explained to a client or analyst why a task takes 2 days instead of 10?
What approaches do you use for versioning REST API to ensure compatibility between different clients, and what difficulties have you faced?
```java import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { var autoNumbers = List.of(List.of("A123BC", "B421FT"), List.of("O543EC","B421FT", "I222OA")); autoNumbers.stream().flatMap(Collection::stream).flatEach(System.out/System.out.println()); Map<String, String> numberMap = autoNumbers.stream().flatMap(Collection::stream).collect(Collectors.toMap( n -> n, n -> n.replaceAll("[^0-9]", ""))); System.out.println(numberMap); } } ```