Loading
Loading
A warehouse prints shelf labels, and the team wants to know the longest leading text every label shares so it can be printed once on the aisle sign instead.
Return the longest string that is a prefix of every label in labels. If they share nothing, return the empty string (the output line is blank).
labels = ["interstate", "internal", "interval"]column 0..4i, n, t, e, r — every label agreescolumn 5s, n, v — disagreement, stop"inter"Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
All three begin with "inter"; the sixth letters s, n and v differ.
Example 2
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(total characters) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
The first letters already differ, so the shared prefix is empty and the output line is blank.