FastPrepRobot Stops Left or Right (Forward Deployed Engineer)
Problems/Robot Stops Left or Right (Forward Deployed Engineer)

Robot Stops Left or Right (Forward Deployed Engineer)

Boston Consulting Group logoBoston Consulting Group● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Boston Consulting Group online assessment for an AI Forward Deployed Engineer role. It was one of four coding tasks. A robot on a line follows left and right moves, and you say which side of its start it stops on.

The report shows the full task and one example, but no input limits. Here, the string has 1 to 1000 characters, and each one is L or R.

Our version is about 95% the same as the reported question.

Given a string commands of L and R moves, return "L" if a robot stops to the left of its starting position, "R" if it stops to the right, or an empty string "" if it stops at its starting position.

The robot moves along a horizontal line and carries out the commands in order. Each L moves it one step to the left, and each R moves it one step to the right. The robot stops after the last command.

Note: a solution with time complexity no worse than O(commands.length^2) is fast enough.

Function

solution(commands: String) → String

Examples

Example 1

commands = "RLLRLL"return = "L"

The first two commands, R and then L, bring the robot back to its starting position. The third and fourth commands, L and then R, bring it back again. The last two commands are both L, so the robot stops two steps to the left.

Example 2

commands = "LRRRL"return = "R"

There are three R moves and two L moves. The robot stops one step to the right of its starting position.

Example 3

commands = "LLRR"return = ""

Two steps to the left and then two steps to the right bring the robot back to its starting position, so the answer is an empty string.

Constraints

  • 1 <= commands.length <= 1000
  • commands contains only the characters L and R.

More Boston Consulting Group interview questions

  • Build Taxi Driver Performance FeaturesOA · Seen Nov 2026
  • Summarize Taxi Drivers and RidesOA · Seen Nov 2026
  • Competition Winner and Runner-Up (Forward Deployed Engineer)OA · Seen Nov 2026
  • Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)OA · Seen Nov 2026
  • Split a Matrix Into Four Partitions by Average (Forward Deployed Engineer)OA · Seen Nov 2026
  • Predict Taxi Driver ClassesOA · Seen Oct 2026
  • Prepare Taxi Driver Classification DataOA · Seen Oct 2026
  • Even-Position MonotonicityOA · Seen Jul 2026
  • Shortest Distances From an Adjacency MatrixPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Branch with the Most FilesCapital One · OACapital One interview questions
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • REST API: Highest International StudentsRippling · OARippling interview questions
  • Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
  • Filter Isolated Interior Signal BitsSEDEMAC · OA
  • Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
  • Telephone Keypad String EncodingEpic · OAEpic interview questions
  • Count Invalid Log GroupsIBM · OAIBM interview questions
  • Count Case-Insensitive TripletsTikTok · OATikTok interview questions
  • Simulate a Deterministic Finite AutomatonPoint72 · OAPoint72 interview questions
All Boston Consulting Group interview questionsSee Boston Consulting Group hiring insights
Saved
class Solution {
    public String solution(String commands) {
        // Write your code here.
    }
}
Checking account…