FastPrepRobot Survival Probability
Problems/Robot Survival Probability

Robot Survival Probability

InMobi logoInMobi● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi onsite interview. A related report uses knight moves. This version follows the clearer report with four-direction robot moves. Our version is about 93% the same as that report.

A robot starts at cell (startRow, startCol) on a rectangular grid with rows rows and cols columns. Rows and columns are zero-indexed.

At every step, the robot independently chooses one of four moves with equal probability: up, down, left, or right. If a move takes it outside the grid, the robot is destroyed immediately.

Return the probability that the robot is still on the grid after exactly steps moves.

Function

robotSurvivalProbability(rows: int, cols: int, startRow: int, startCol: int, steps: int) → double

Examples

Example 1

rows = 3cols = 3startRow = 1startCol = 1steps = 1return = 1.0

From the center of a 3-by-3 grid, all four one-step moves remain inside.

Example 2

rows = 3cols = 3startRow = 0startCol = 0steps = 1return = 0.5

From a corner, two of the four equally likely moves stay inside, so the survival probability is 2 / 4 = 0.5.

Example 3

rows = 2cols = 2startRow = 0startCol = 0steps = 2return = 0.25

The robot has probability 1 / 2 of surviving each move from any corner of this grid, so the two-step probability is 1 / 4.

Example 4

rows = 1cols = 1startRow = 0startCol = 0steps = 0return = 1.0

Before any move is made, the robot is still at its valid starting cell.

Constraints

  • 1 <= rows, cols <= 50
  • 0 <= startRow < rows
  • 0 <= startCol < cols
  • 0 <= steps <= 100
  • Answers within 10^-9 of the expected value are accepted.

More InMobi Onsite Interview questions

  • Russian Doll EnvelopesONSITE INTERVIEW · Seen Jul 2026
  • Minimum and Maximum with Optimal ComparisonsONSITE INTERVIEW · Seen Dec 2025
  • Minimum Edges to Connect All ComponentsONSITE INTERVIEW · Seen Dec 2025
  • Shortest Path Visiting All NodesONSITE INTERVIEW · Seen Sep 2025
  • Maximum Sum of Non-Adjacent Tree NodesONSITE INTERVIEW · Seen Jan 2022
  • Word SquaresONSITE INTERVIEW · Seen Jan 2022
  • Maximum Length Pair ChainONSITE INTERVIEW · Seen Jul 2021
  • Top View of a Binary TreeONSITE INTERVIEW · Seen Jul 2021
  • Maximum XOR Between Two ArraysONSITE INTERVIEW · Seen May 2021
  • Trapping Rain WaterONSITE INTERVIEW · Seen May 2021

Similar questions at other companies

  • Knight Probability in ChessboardGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Trace Every Water Drop to Its Resting DestinationGoogle · ONSITE INTERVIEWGoogle interview questions
  • Multi-Head Self-Attention LayerOpenAI · ONSITE INTERVIEWOpenAI interview questions
  • Implement Circular PaddingApple · ONSITE INTERVIEWApple interview questions
  • Grouped-Query Attention with a KV CacheAmazon · ONSITE INTERVIEW
  • Two-Player Gambler's Ruin Probability and SimulationMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Logistic Regression DiagnosticsLinkedIn · PHONE SCREENLinkedIn interview questions
  • Scaled Dot-Product AttentionMeshy · OA
  • Longest Border-Ending Diagonal PatternZipRecruiter · OAZipRecruiter interview questions
  • Column and Row Parallel Linear LayersNVIDIA · PHONE SCREENNVIDIA interview questions
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public double robotSurvivalProbability(int rows, int cols, int startRow, int startCol, int steps) {
        // write your code here
    }
}
Checking account…