0% found this document useful (0 votes)
7 views4 pages

problem on String

It is a python problem solving programming. It can be used for interview or placement learning purpose.

Uploaded by

dhanyasri921
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

problem on String

It is a python problem solving programming. It can be used for interview or placement learning purpose.

Uploaded by

dhanyasri921
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CODE GALATA

Scenario: Longest Common Prefix in Customer Feedback


Imagine you are managing customer feedback for a product. You receive
multiple feedback entries from different customers. To analyze trends, you want
to find the longest common prefix shared by all feedback entries. This helps in
identifying common patterns or phrases that customers use, which can be
critical for improving the product or marketing strategies.
Your task is to write a function that identifies the longest common prefix among
an array of feedback entries. If no common prefix exists, the function should
return an empty string.

Sample Test Cases with Detailed Explanations Test Case 1


Input: feedback = ["flower", "flow", "flight"]
Output: "fl"
Explanation:
• All feedback entries share the prefix "fl".
• "flower" starts with "fl".
• "flow" starts with "fl".
• "flight" starts with "fl".

Test Case 2
Input: feedback = ["dog", "racecar", "car","apple"]
Output: ""
Explanation:
• There is no common prefix among the feedback entries.
• "dog" does not share any prefix with "racecar" or "car".
Test Case 3
Input: feedback = ["interspecies", "interstellar", "interstate"]
Output: "inters"
Explanation:
• All feedback entries share the prefix "inters".
• "interspecies" starts with "inters".
• "interstellar" starts with "inters".
• "interstate" starts with "inters".

Test Case 4
Input: feedback = ["throne", "throne", "throne"]
Output: "throne"
Explanation:
• All feedback entries are identical.
• The common prefix is the entire string "throne".

Test Case 5
Input: feedback = ["reflower", "flow", "flight"]
Output: ""
Explanation:
• The entries do not share a common prefix.
• "reflower" does not share any prefix with "flow" or "flight".
Constraints
• 1 <= feedback.length <= 200
• 0 <= feedback[i].length <= 200
• feedback[i] consists of only lowercase English letters.
Scenario: Finding the Largest Odd Substring in Financial Transactions
Imagine you are developing a financial application where you need to process a
string representing a large transaction ID. Your task is to extract the largest-
valued odd integer from this string. This is useful for identifying certain types of
transactions that end with odd digits, which may be flagged for special
processing or auditing.
You need to write a function that takes a string of digits (representing the
transaction ID) and returns the largest-valued odd integer that is a non-empty
substring of this string. If no odd integer exists, the function should return an
empty string.
Sample Test Cases with Detailed Explanations Test Case 1
Input: transaction_id = "52"
Output: "5"
Explanation:
• The substrings are "5", "2", and "52".
• "5" is the only odd number.
Test Case 2
Input: transaction_id = "4206"
Output: ""
Explanation:
• The substrings are "4", "2", "0", "6", "42", "420", "4206", etc.
• None of these substrings are odd numbers.
Test Case 3
Input: transaction_id = "35427"
Output: "35427"
Explanation:
• "35427" is already an odd number, as it ends with the digit "7".
Test Case 4
Input: transaction_id = "1234567890"
Output: "123456789"
Explanation:
• The largest-valued odd integer is "123456789".

Test Case 5
Input: transaction_id = "88888"
Output: ""
Explanation:
• All digits are even, so no odd numbers exist.
Constraints
• 1 <= transaction_id.length <= 10^5
• transaction_id only consists of digits and does not contain any leading
zeros.

You might also like