Lazy Chef: Group One Ingredient
Updated
Problem statement
Each character of ingredients represents a block containing one ingredient. In one move, swap two adjacent blocks. Find the minimum moves required to make all occurrences of target consecutive anywhere in the sequence. Other ingredients may appear in any remaining order. target is a one-character string and occurs at least once.
Function
groupIngredient(ingredients: String, target: String) → longExamples
Example 1
ingredients = "HDHSAHS"target = "H"return = 3Three adjacent swaps can group the H blocks; arbitrary nonadjacent swaps are not allowed.
Example 2
ingredients = "ABBBBA"target = "A"return = 4Moving the two A blocks together crosses four intervening B blocks.
Constraints
- 1 <= ingredients.length <= 100000, and the target occurs.
- For this exercise, assume uppercase ASCII letters and return a signed 64-bit move count.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
- Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
- Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
- Minimum Binary Swaps to a PalindromeAT&T · OAAT&T interview questions
- Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimum Additions to Make a Valid ABC StringIBM · OAIBM interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Minimum Adjacent TranspositionsEpic · OAEpic interview questions
- Maximum String OperationsMicrosoft · OAMicrosoft interview questions