Create a program to find the longest common prefix among an array of strings.
HardProblem Statement
Create a program to find the longest common prefix among an array of strings.
Sample Input
A hardcoded array, e.g., ["flower", "flow", "flight"].
Sample Output
Longest common prefix: fl
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
fun longestCommonPrefix(strings: Array<String>): String {
// Add your code here to find the longest common prefix
}
fun main() {
val strings = arrayOf("flower", "flow", "flight")
println("Longest common prefix: ${longestCommonPrefix(strings)}")
}
Input
A hardcoded array, e.g., ["flower", "flow", "flight"].
Expected Output
Longest common prefix: fl