Dsa
Trie
Easy
Common Prefix Length
Given a list of words, your task is to find the length of the longest common prefix among all of them. Write a program that reads a list of words and outputs the length of the longest common prefix.
Input format:
- The first line contains an integer N, the number of words.
- The next N lines each contain a single word consisting of lowercase letters only.
Output format:
- Output a single integer representing the length of the longest common prefix.
Example:
Input:
3
flower
flow
flight
Output:
2
Key concepts
trieprefixstrings
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now