Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a program to find the longest common prefix among an array of strings.

Hard

Problem 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)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded array, e.g., ["flower", "flow", "flight"].
Expected Output
Longest common prefix: fl