Knight Survival Probability
Updated
Problem statement
A knight starts at (row,column) on a size by size board, indexed from 0. At each step it independently chooses one of all eight knight displacements with probability 1/8: move two cells along one axis and one along the other.
Return the probability that it stays on the board throughout exactly moves steps. A move off the board ends that path; do not renormalize among legal moves. Zero moves has probability 1.
Answers are accepted within an absolute tolerance of 0.000001, matching the source six-decimal output precision.
Function
knightSurvival(size: int, moves: int, row: int, column: int) → doubleExamples
Example 1
size = 3moves = 2row = 0column = 0return = 0.0625From a corner of the 3x3 board, two of eight moves survive each step. The probability is (2/8)^2=0.0625.
Example 2
size = 1moves = 0row = 0column = 0return = 1.0No move is made, so the knight remains at its valid starting cell.
Constraints
1 <= size <= 25.0 <= moves <= 100.0 <= row, column <= 24.- Both starting coordinates are smaller than size.
More Expedia Online Assessment questions
- Balanced NumbersOA · Seen Aug 2026
- REST API: Discounted PriceOA · Seen Aug 2026
- Maximum Team SizeOA · Seen Mar 2026
- Per-Domain Request LimiterOA · Seen Oct 2025
- Count Equal-Frequency SubsequencesOA · Seen Mar 2025
- Count Increasing Stock PeriodsOA · Seen Mar 2025
- Get Minimum StepsOA · Seen Oct 2024
- Rank Songs by PopularityOA · Seen Oct 2024
- Calculate the SumOA · Seen Oct 2024
- Get Maximum EfficiencyOA · Seen Oct 2024
Similar questions at other companies
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-Step RuleUber · OAUber interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Unique Paths Through a GridPeopleStrong · OAPeopleStrong interview questions
- Get Minimum OperationsJP Morgan Chase · OAJP Morgan Chase interview questions
- Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
- Find Encrypted NumberAmazon · OA
- Prime StringSnowflake · OASnowflake interview questions
Interview reports that mention this question
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)