package core

import "strings"

// LongestCommonPrefix returns the longest string that is a prefix of every item.
// Returns "" if the slice is empty or no common prefix exists.
func LongestCommonPrefix(items []string) string {
	if len(items) == 0 {
		return ""
	}
	prefix := items[0]
	for _, item := range items[1:] {
		for !strings.HasPrefix(item, prefix) {
			if prefix == "" {
				return ""
			}
			prefix = prefix[:len(prefix)-1]
		}
	}
	return prefix
}
