Frontend School

Myntra Customer Service Request Prioritizer

DSA
easy

Myntra Customer Service Request Prioritizer

Easy
Queue
Arrays

Overview

Myntra's customer support system handles a continuous stream of customer requests. To maintain high service standards and address critical issues efficiently, requests marked as "escalated" must be prioritized over "normal" requests. This problem focuses on implementing a system to reorder incoming requests based on their priority before they are dispatched to agents.

What you need to do / Task

You are tasked with implementing a function that takes an array of customer support request objects. Each request has a unique ID and a priority level. Your function must return an array of requestIds, reordered according to the following rules:

  1. All requests with priority: 'escalated' must appear before any requests with priority: 'normal'.
  2. The relative order of requests within the 'escalated' group must be preserved from the original input.
  3. The relative order of requests within the 'normal' group must be preserved from the original input.

Input & output

The function prioritizeRequests will take one parameter:

  • requests: An array of objects, where each object represents a customer support request.
    • Each request object has two properties:
      • requestId (number): A unique identifier for the request.
      • priority (string): Can be either 'normal' or 'escalated'.

The function must return:

  • An array of numbers, representing the requestIds in their prioritized order.

Clarifications

  • The input requests array will not be empty.
  • requestIds are guaranteed to be unique.
  • The priority field will only ever be 'normal' or 'escalated'.

Examples

1

Example 1

Input:

requests = [{"requestId": 101, "priority": "normal"}, {"requestId": 102, "priority": "escalated"}, {"requestId": 103, "priority": "normal"}, {"requestId": 104, "priority": "escalated"}]

Output:

[102, 104, 101, 103]

Note:

Requests 102 and 104 are escalated and appear first, maintaining their original relative order. Requests 101 and 103 are normal and appear after, also maintaining their original relative order.

2

Example 2

Input:

requests = [{"requestId": 201, "priority": "normal"}, {"requestId": 202, "priority": "normal"}, {"requestId": 203, "priority": "normal"}]

Output:

[201, 202, 203]

Note:

All requests are normal, so their original order is preserved.

3

Example 3

Input:

requests = [{"requestId": 301, "priority": "escalated"}, {"requestId": 302, "priority": "escalated"}, {"requestId": 303, "priority": "escalated"}]

Output:

[301, 302, 303]

Note:

All requests are escalated, so their original order is preserved.

Constraints

Constraints & assumptions

  • 1 <= requests.length <= 1000
  • 1 <= requestId <= 10^9
  • Time complexity: O(N) where N is the number of requests.
  • Space complexity: O(N) where N is the number of requests.

What interviewers evaluate

  • Correctness of the prioritization logic for both priority groups.
  • Efficient use of data structures (e.g., arrays acting as queues) to solve the problem.
  • Clarity and readability of the code.
  • Handling of edge cases (e.g., all requests are normal, all are escalated).

Loading editor...