Compare all possible prefixes
Solution Breakdown
HOW-TO: Generating all prefixes from a string
Prefixes of the word flower:
"f"
"fl"
"flo"
"flow"
"flowe"
"flower"Method 1: String concatenation with a loop
word = "flower"
prefix = ""
for i in range(len(word)):
prefix += word[i]
print(f"Current Prefix: {prefix}")Method 2: String slicing with a loop
Pseudocode
Python Solution
Code Explanation
Connected Readings
PreviousLongest Common Prefix - LeetCodeNextCreate the longest common prefix with the direct neighbour
Last updated