#45API Endpoint Grouping
A company has multiple API endpoints used by different services. To identify which endpoints belong to the same service group, the system needs to find the longest common prefix shared by all given API endpoint paths.
Given an array of API endpoint strings, return the longest common prefix shared by every endpoint. If there is no common prefix, return an empty string.
For example, the endpoints "/api/users", "/api/orders", and "/api/products" share the prefix "/api/".
Real-World Applications: API Service Route Grouping; Microservice Route Detection; API Gateway Routing;
Examples
Example 1
Input: endpoints = ["/api/users","/api/orders","/api/products"]
Output: "/api/"
Explanation: All three API endpoints start with /api/, and there is no longer prefix common to all of them.
Example 2
Input: endpoints = ["/service/payment","/service/profile","/service/product"]
Output: "/service/p"
Explanation: All endpoints share /service/p. After p, the endpoints contain different characters.
Example 3
Input: endpoints = ["/v1/users","/v1/user-details","/v1/user-settings"]
Output: "/v1/user"
Explanation: All three endpoints start with /v1/user, but the next characters are different.
Constraints
- 1 <= endpoints.length <= 200
- 0 <= endpoints[i].length <= 200
- Endpoints contain lowercase English letters, digits, /, -, and _.
- Each endpoint represents a valid API route.