This is a verified interview question from Blackrock. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Java: Airport Baggage Handling System - Blackrock Online Assessment Manipal University 8 August 202" covers key patterns like System Design.
"Assessment Pattern: 97 Q( 2 Coding + 95 Mcqs) | No. | Section | Questions | Duration | | --: | ---------------------------------------------------------------- | --------: | ---------- | | 1 | **Coding (Advance programming fundamentals)** | 1 | 40 minutes | | 2 | **Coding (Basic Programming)** | 1 | 15 minutes | | 3 | **Design Pattern (Advanced)** | 15 | 6 minutes | | 4 | **Design Pattern (Basic)** | 15 | 4 minutes | | 5 | **Fundamental AI know how, Cloud Services Exposure** | 25 | 10 minutes | | 6 | **DB Concepts - ACID properties, Transactions, DB Fundamentals** | 25 | 10 minutes | | 7 | **Aptitude** | 15 | 10 minutes | ### Total * **Questions:** 97 * **Duration:** 95 minutes Implement an airport baggage sorting system that efficiently categorizes items by destination using parallel processing. Each baggage item, identified by its name and destination, should be grouped accordingly, leveraging the Fork-Join Framework for parallel sorting. **Goal** * Sort a list of baggage items by their assigned destinations using either sequential sorting (sorting via ascending order of their arrival time) or a divide-and-conquer approach based on the constraints outlined in the `compute()` function description. * Display each destination, sorted alphabetically in ascending order, along with its assigned baggage names sorted as per the given defined rule. **Note:** * It is guaranteed that there are no duplicate baggage or destination names. * Each bag's destination is included in the given list of destinations. --- ### **Classes and Methods** **`class BaggageItem`** Each object of this class contains: * `name`: The bag's name, e.g., "BagA". * `destination`: The bag's destination, e.g., "Paris". **`class BaggageSorter extends RecursiveTask<Map<String, List<BaggageItem>>>`** It handles parallel sorting of baggage items using the Fork-Join Framework, extending `RecursiveTask` for recursive task decomposition. Its attributes are: * `baggageItems`: A list of all baggage items to sort. * `start`: The start index of the list for the current task. * `end`: The end index of the list for the current task. **`Map<String, List<BaggageItem>> sortBaggage(int numberOfBags, List<BaggageItem> baggageItems)`** The method manages parallel sorting of baggage items. * It creates a `ForkJoinPool`. * It invokes the `BaggageSorter` task to perform parallel sorting. * It returns a map with destination names as keys and sorted lists of corresponding baggage items as values. --- ### **Function Description** Complete the function `compute()` in the editor. It sorts the baggage items based on their destinations either using sequential sorting or in parallel using the Fork-Join Framework. * If the task is small (10 or fewer baggage items): Sort sequentially i.e., sorting as per the baggage arrival time. * If there are more than 10 baggage items, split the task into left and right subtasks, sort both in parallel, merge the left into the right, i.e., right = right + left, and return the right subtask as the final sorted result. **Function Parameters** No parameters, but the class has access to `baggageItems`, `start`, and `end` to define the scope of work for each subtask. **Returns** `Map<String, List<BaggageItem>>`: where the key is a destination, e.g., "Paris", and the value is a list of baggage items assigned to that destination. --- ### **Constraints** * 1 ≤ numberOfBags ≤ 30 * 1 ≤ numberOfDestinations ≤ 20 * Each bag's name will be a non-empty string that may contain a single whitespace with 1 to 20 alphanumeric characters. Boilerplate code template ```java import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.util.concurrent.*; // Class representing a baggage item with a name and destination class BaggageItem { private final String name; private final String destination; public BaggageItem(String name, String destination) { this.name = name; this.destination = destination; } public String getName() { return name; } public String getDestination() { return destination; } @Override public String toString() { return name + ": " + destination; } } // RecursiveTask for parallel sorting of baggage items by destination class BaggageSorter extends RecursiveTask<Map<String, List<BaggageItem>>> { private final List<BaggageItem> baggageItems; private final int start; private final int end; public BaggageSorter(List<BaggageItem> baggageItems, int start, int end) { this.baggageItems = baggageItems; this.start = start; this.end = end; } @Override protected Map<String, List<BaggageItem>> compute() { // Write code here } } ```"
Join thousands of developers practicing for Blackrock.