This is a verified interview question from Uber. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Route Consolidation - Uber Online Assessment IIT Roorkee" covers key patterns like Arrays.
"### Problem Statement Uber's routing engine represents a driver's itinerary as a sequence of trip segments. You are given two itineraries represented by arrays A and B, where each element denotes the distance of a consecutive trip segment. To simplify routes, the routing engine can perform the following operation any number of times: Select two adjacent segments in an itinerary and merge them into a single segment whose distance is the sum of the two segments. For example, [1, 4, 7, 2] → [5, 7, 2] [2, 3, 6, 2] → [6, 2, 1, 2] [6, 1, 4, 1] → [5, 6, 3] After performing operations on either itinerary, both itineraries must satisfy: - They contain the same number of segments. - The distance of the i-th segment in both itineraries is identical. Determine the maximum possible common number of segments that can be achieved. If it is impossible to transform the itineraries to satisfy the above conditions, return -1. ### Input N, M A1 A2 ... AN B1 B2 ... BM ### Output Print the maximum common itinerary length after consolidation, or -1 if no valid transformation exists."
Join thousands of developers practicing for Uber.