Loading...
Loading...
The exam cell has a list of n course codes, such as CS101, CS102 and CS110. To print one heading for the list, they need the longest starting part that every code shares. For these three codes it is CS1.
Print that shared start. If the codes do not even share the first character, print NONE.
NONE.Example 1
Input
3 CS101 CS102 CS110
Output
CS1
All three codes start with CS1. The fourth characters 0, 0 and 1 differ.
Example 2
Input
3 ME201 EE201 CE201
Output
NONE
The first characters already differ.
Try the problem first. Open one hint at a time.
The shared start can never be longer than the shortest code.
Take the first code as the current answer. Compare it with each other code and keep only the matching start.
For each code, the answer length becomes the number of matching characters from the left, up to the shorter length.
If the length drops to 0 at any point, the answer is NONE.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor