Limited Time Offer:Up to 20% off Hello Interview Premium
Up to 20% off Hello Interview Premium 🎉
Hello Interview
Your Dashboard
System Design
Code
Low Level Design
Behavioral
AI Coding
New
ML System Design
Salary Negotiation
Interview Guides
Blog
System Design
Low Level Design
AI Coding
Behavioral
New
Interview Questions
Success Stories
System Design
Low-Level Design
New
Ask The Community
Discord
Mock Interviews
1:1 Mentorship
Refer a Friend
Pricing
Sign in / Sign up
Search
⌘K
Pricing

Tutor

Minimize Weighted Subsequence Pair Errors with Wildcards

Given a string containing '0', '1', and '!' characters, replace each '!' with either '0' or '1' to minimize the total weighted errors, where each '01' subsequence pair contributes x errors and each '10' subsequence pair contributes y errors. Return the minimum total errors modulo 10^9 + 7.

Asked at:

Amazon

Amazon


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Company
​
Level
All Regions
Region

Late July, 2025

Amazon

Amazon

Senior

You are given a string s containing only '0', '1', and '!'. Each '!' must be replaced by either '0' or '1'. After all replacements, consider every pair of indices (i, j) with i < j: if the characters form 01, that pair contributes x errors if the characters form 10, that pair contributes y errors These are subsequence pairs, not substrings, so the two characters do not need to be adjacent. Return the minimum total number of errors possible after replacing all '!'. Because the answer can be large, return it modulo 10^9 + 7. Example: errorString = "101!1" x = 2 y = 3 - If the '!' at index 3 is replaced with '0', the string is '10101'. The number of times the subsequence 01 occurs is 3 at indices (1,2), (1,4) and (3,4). The number of times the subsequence 10 occurs is also 3, indices (0,1), (0,3) and (2,3). The number of errors is 3x + 3y = 15. - If the '!' is replaced with '1', the string is '10111'. The subsequence 01 occurs 3 times and 10 occurs 1 time. The number of errors is 3x + y = 9 The minimum number of errors is min(9, 15) = 9 Similar: https://prachub.com/coding-questions/maximize-weighted-subsequence-pairs-with-wildcards

Your account is free and you can post anonymously if you choose.

Hello Interview Premium

Recent interview questions
System Design Guided Practice
Exclusive content
Learn More
Questions
Meta SWE Interview QuestionsAmazon SWE Interview QuestionsGoogle SWE Interview QuestionsOpenAI SWE Interview QuestionsEngineering Manager (EM) Interview Questions
Learn
Learn System DesignLearn DSALearn BehavioralLearn ML System DesignLearn Low Level DesignGuided Practice
Links
FAQPricingGift PremiumHello Interview Premium
Legal
Terms and ConditionsPrivacy PolicySecurity
Contact
About UsProduct Support

7511 Greenwood Ave North Unit #4238 Seattle WA 98103


© 2026 Optick Labs Inc. All rights reserved.