Loading...
Loading...
Loading...
Student IDs in one batch often start the same way, like cse21001, cse21045 and cse21310. Read n IDs and print the longest beginning that all of them share. If they share nothing, print None.
None.Example 1
Input
3 flower flow flight
Output
fl
Example 2
Input
3 dog racecar car
Output
None
The first letters already differ.
Try the problem first. Open one hint at a time.
Start with the first ID as the prefix.
For each other ID, while it does not startsWith the prefix, cut the last character off the prefix.
If the prefix becomes empty, nothing is shared.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor