Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

44. Longest Common Prefix

EasyDay 14 of 60Strings

Given an array of strings strs, return the longest string that is a prefix of every string in the array. If the strings share no common prefix, return the empty string "".

Example 1
Input: strs = ["flower","flow","flight"]
Output: "fl"
Example 2
Input: strs = ["dog","racecar","car"]
Output: ""
The first letters already differ.
Constraints
  • 1 <= strs.length <= 200
  • 0 <= strs[i].length <= 200
  • Strings contain only lowercase English letters
Hints
Frequently asked at: Amazon, Google, Apple, Infosys, Cognizant
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min