Question 1
Medium Implement a URL request-handler router with two operations. processHandler(handler) registers a route template such as /users/delete or /users/{userId}/photo/{photoId}. getHandler(url) returns the registered template that matches a concrete URL such as /users/123/photo/456.
Matching rules: paths are non-empty segments separated by /; a {name} segment matches any one non-empty segment; a literal segment must match exactly; template and URL must have the same number of segments; if several match, prefer the template with more literal matches, then the one registered earliest; return NOT_FOUND if none match. Ignore query strings, fragments, URL encoding, and HTTP methods.
Input: first line Q; then Q lines "REGISTER <handler>" or "GET <url>".
Output: for each GET, the matching template or NOT_FOUND.
Example: REGISTER /users/{userId}/photo/{photoId}, REGISTER /users/delete, REGISTER /users/{userId}; GET /users/123/photo/456 gives /users/{userId}/photo/{photoId}; GET /users/delete gives /users/delete; GET /users/abc/settings gives NOT_FOUND.
Constraints: 1 <= Q <= 100000; at most 100 segments per path; total input path length at most 1,000,000.