FastPrepMaximum Number of Workers with Equal Left and Right Shoes
Problems/Maximum Number of Workers with Equal Left and Right Shoes

Maximum Number of Workers with Equal Left and Right Shoes

Tesla logoTesla● EasyINTERNOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

Ellen would like to assign this task to her subordinate workers. Each worker should get a distinct interval of adjacent shoes, such that the number of left shoes is equal to the number of right shoes. Each shoe must be assigned to exactly one worker.

What is the maximum number of workers that Ellen can assign to this task?

Write a function:

class Solution { public int solution(String S); }

that, given a string S of letters "L" and "R", denoting the types of shoes in line (left or right), returns the maximum number of intervals such that each interval contains an equal number of left and right shoes.

Write an efficient algorithm for the following assumptions:

  • N is an integer within the range [2..100,000];
  • String S is made only of the characters 'R' and/or 'L';
  • The number of letters "L" and "R" in string S is the same.

Another problem from the same batch:

Function

teslaShoeFactory(S: String) → int

Examples

Example 1

S = "RLRRLLRLRRLL"return = 4

Because S can be split into intervals: "RL", "RRLL", "RL" and "RRLL". Note that the intervals do not have to be of the same size.

Example 2

S = "RLLLRRRLLR"return = 4

The function should return 4, because S can be split into intervals: "RL", "LLRR", "RL" and "LR".

Example 3

S = "LLRLRLRLRLRLRR"return = 1

The function should return 1.

More Tesla interview questions

  • Flatten a Branched List into a Doubly Linked ListPHONE SCREEN · Seen Sep 2026
  • Reduce-Based Map and Filter PipelinePHONE SCREEN · Seen Sep 2026
  • Resilient Fake API ClientPHONE SCREEN · Seen Sep 2026
  • Alternate Positive and Negative ValuesONSITE INTERVIEW · Seen Aug 2026
  • Enumerate Character Paths to a MarkerONSITE INTERVIEW · Seen Aug 2026
  • Shared Counter Snapshot SumONSITE INTERVIEW · Seen Aug 2026
  • Merge JSON Array FieldsPHONE SCREEN · Seen Aug 2026
  • Count Zero-Sum FragmentsOA · Seen Jun 2026
  • Maximum Insertions Without Three Consecutive AOA · Seen Jun 2026
  • KV Store with RollbackPHONE SCREEN · Seen Apr 2026

Similar questions at other companies

  • Longest Repeated Letter Block with Adjacent SwapsIntuit · OAIntuit interview questions
  • Maximum Equalized Substrings After One Adjacent SwapVisa · OAVisa interview questions
  • Minimum Changes for Distinct Adjacent CharactersHeadlands Technologies · OAHeadlands Technologies interview questions
  • Fill One Exact-Length Binary WindowAmazon · OA
  • Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
  • Minimum AmountBelvedere Trading · OA
  • Prepare NotificationMicrosoft · OAMicrosoft interview questions
  • Largest Number With Even Digit FrequenciesDRW · OADRW interview questions
  • Minimum Replacements for Unequal Adjacent CharactersIBM · OAIBM interview questions
  • Crop Text at a Whole-Word BoundaryAmerican Express · OAAmerican Express interview questions

Tesla interview experiences

  • Tesla Experienced Infrastructure SWE Interviews: 1 Experience
  • Tesla Older SWE Intern Reports: 14 Experiences (Part 4 of 4)
  • Tesla Embedded and SRE Intern Loops: 15 Experiences (Part 3 of 4)
  • Tesla SWE and Data Intern Rounds: 10 Experiences (Part 2 of 4)
  • Tesla Intern Python Interview Prep Guide
  • 2017–2026 Tesla Intern OA / Interviews: 83 Experiences (Part 2 :)
All Tesla interview questionsSee Tesla hiring insights
Saved
class Solution {
    public int teslaShoeFactory(String S) {
      // write your code here
    }


}
Checking account…