The longitude constraint alone would just be longest increasing subsequence, which I spotted pretty fast.
Recognize this as a 2D longest increasing subsequence (LIS) problem where each city is a point (longitude, name). Sort cities by longitude, then find the longest strictly increasing subsequence of names using an O(n log n) patience sorting approach with binary search on the tails array.
Pro tip: Clarify whether 'lexicographically greater' uses standard string comparison (e.g., 'apple' < 'banana') and whether case matters; also confirm if longitudes are unique, as duplicates would require careful handling to avoid invalid sequences.
Restate the problem in your own words and ask clarifying questions about lexicographic order, case sensitivity, and duplicate longitudes.
Explain that each city is a point (longitude, name) and we need the longest chain where both coordinates strictly increase.
Sort the cities by longitude ascending. If longitudes can be equal, handle ties by sorting names descending to prevent invalid sequences in the LIS step.
Use the O(n log n) patience sorting algorithm: maintain a tails array and for each name, binary search for the first tail >= name and replace it, or append if none.
The size of the tails array is the maximum number of cities visitable. Optionally, reconstruct the sequence if needed.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.