File: root - text - article - 2020 - 02 - staying-on-a-chess-board.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 654 Views, 27596 Search Bots | 94 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 654 Views, 27596 Search Bots | 94 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Google:
A chess board is an 8x8 grid. Given a knight at any position (x, y) and a number of moves k, we want to figure out after k random moves by a knight, the probability that the knight will still be on the chessboard. Once the knight leaves the board it cannot move again and will be considered off the board.
Here's some starter code:
def is_knight_on_board(x, y, k, cache={}):
# Fill this in.
print is_knight_on_board(0, 0, 1)
# 0.25
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 654 Views, 27596 Search Bots | 94 Words A chess board is an 8x8 grid. Given a knight at any position (x, y) and a number of moves k, we want to figure out after k random moves by a knight, the probability that the knight will still be on the chessboard. Once the knight leaves the board it cannot move again and will be considered off the board.
Here's some starter code:
def is_knight_on_board(x, y, k, cache={}):
# Fill this in.
print is_knight_on_board(0, 0, 1)
# 0.25
Related Articles
- [Daily Problem] Course Prerequisites
- Staying on a Chess Board
- Daily Interview Problem: Largest BST in a Binary Tree
- Reverse a Directed Graph
- Daily Interview Problem: Find the k-th Largest Element in a List
- Algorithm Interview: Determine If Linked List is Palindrome
- Daily Interview Problem: Minimum Removals for Valid Parenthesis
- Two-Sum
- Algorithm Interview Question: Symmetric k-ary Tree
- Algorithm Interview Question: H-Index
©2006~2024 SteakOverCooked - 0.01205 Seconds(s) - 4441.86 KB/s - 101 Online Memory: 527.63 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !