Question: python solution for There are N players standing in a row, one player on a field. They are numbered from 0 to N 1 from
python solution for There are N players standing in a row, one player on a field. They are numbered from to N from left to right. Players perform moves one by one from left to right, that is in ascending order of numbers. Each player presses an arrow key in one of the four cardinal left right up or down A key press in the given direction means that the player attempts to move onto the closest field in the direction specified. A move can be performed only if there is no other player already standing on the target field. Moves are represented as a string S of length N where SKfor K within the range N is the direction of the Kth player's move. How many players will actually perform a move successfully? Write a function: class Solution public int solutionString S; which, given a string S of length N representing arrow keys pressed by each of the players, returns the number of players that will perform a move successfully. Examples: leftwards, because player is standing on the target field. Players and can both perform their moves because there are other play stang their target fields. In the pictures below, players that will perform their moves successfully are marked green and players whose moves will fail are marked red. Given S your function should return Players can all perform their moves because there are no other players standing on their target fields. Player pressed the rightarrow key, but the move cannot be performed as player is already standing on the target field. The move of player can be performed, though, as there is no other player standing on the target field. Given S your function should return No player can perform a move.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
