Problem Statement
- 'L': Spin left. If the bar is in state '|', it goes to '\'. State '\' goes to '-', '-' goes to '/', and '/' goes to '|'.
- 'R': Spin right. This is the exact opposite of 'L': '\' goes to '|', '|' goes to '/', '/' goes to '-', and '-' goes to '\'.
- 'F': Flip. The bar is rotated 90 degrees: '\' becomes '/', '/' becomes '\', '-' becomes '|', and '|' becomes '-'.
- 'U': The bar moves up.
- 'D': The bar moves down.
- '<': The bar moves left.
- '>': The bar moves right.
Initially, the bar is at (0, 0), which is the upper-left corner of the screen, and it is in state startState. The rest of the screen is empty. You are given a
For example, if your desiredScreen is
{"///", "///", "---"}and your startState is '-', you can achieve that with "L>>D<<DR>>". In this case, it took 10 seconds to get the screen to desiredScreen.
For the given desiredScreen and startState, return the minimum time needed to achieve this goal, or -1 if it is impossible to do so.
Definition
- Class:
- IndicatorMotionDrawing
- Method:
- getMinSteps
- Parameters:
- String[], char
- Returns:
- int
- Method signature:
- int getMinSteps(String[] desiredState, char startState)
- (be sure your method is public)
Notes
- The bar cannot be moved outside the boundary of desiredScreen.
- Note that desiredScreen may contain spaces. The bar can never pass through a cell which has a space in desiredScreen because it would leave a character that would never be erased.
- In the examples the character '\' appears as '\\' because of the C++/Java syntax for escaping characters.
Constraints
- startState will be one of '/', '\', '|', or '-'.
- desiredScreen will have between 1 and 3 elements, inclusive.
- Each element of desiredScreen will contain exactly N characters, where N is an integer between 1 and 4, inclusive.
- Each character of each element of desiredScreen will be one of ' ', '/', '\', '|', or '-'.
Examples
{"///", "///", "---"}
'-'
Returns: 10
The example from the problem statement.
{" ||", "|||", "|||"}
'|'
Returns: -1
Since the bar is initially at (0,0), it's impossible to achieve a desiredScreen that has a space at that location.
{"/- ", "/ ", "/--"}
'/'
Returns: 9
Don't step on spaces! Here, you are forced to step twice at least in (0,0). One way to achieve the best time is "R>
R>". This will lead to this sequence of screens, with dots representing spaces and and the location of the bar written below each screen as (row,column): /.. -.. --. --. /-. /-. /-. /-. /-. /-. ... -> ... -> ... -> ... -> ... -> /.. -> /.. -> /.. -> /.. -> /.. ... ... ... ... ... ... /.. //. /-. /-- (0,0) (0,0) (0,1) (0,0) (0,0) (1,0) (2,0) (2,1) (2,1) (2,2) {"/-|/", "/ |/", "-/\\/"}
'\\'
Returns: 18
{"////"," ","////"}
'/'
Returns: -1
{"\\-\\-","- \\","\\-\\-"}
'-'
Returns: 19
{"-"}
'-'
Returns: 0
{"/"}
'\\'
Returns: 1
{"\\-\\-"}
'-'
Returns: 7
{"/","|","/"}
'|'
Returns: 5
{"| "," "," "}
'|'
Returns: 0
{"---"," -","---"}
'|'
Returns: 7
{"/ /","/ /","///"}
'\\'
Returns: 7
{"/| -"," - \\","\\-|/"}
'|'
Returns: 18
{"/|","| "}
'|'
Returns: 5
{"----","\\\\--","----"}
'\\'
Returns: 14
{"- ","/-\\|","\\ | "}
'/'
Returns: 15
{"-/","/ "}
'-'
Returns: 6
{"-|-|","|-|-","-|-|"}
'|'
Returns: 23
{"-\\|/","/|-\\","\\/-|"}
'/'
Returns: 22
{"/","\\"}
'\\'
Returns: 3
{"/-\\|","|\\-/","-/|\\"}
'\\'
Returns: 23
{"/-\\|","| -/","-/|\\"}
'\\'
Returns: 21
{"/-\\|","|\\ /","-/|\\"}
'\\'
Returns: 21
{"/-\\|"," \\- ","-/|\\"}
'\\'
Returns: 21
{"/-\\|"," \\ ","-/|\\"}
'\\'
Returns: 20
{"/ \\|","|\\- ","- |\\"}
'\\'
Returns: 19
{"---","- -"," - "}
'-'
Returns: -1
{"/ / ","/ //","/// "}
'\\'
Returns: 9
{"- --","\\\\ |","-- /"}
'|'
Returns: -1
{"\\ //"," |||","----"}
'\\'
Returns: -1
{"-/ |"}
'|'
Returns: -1
{"\\\\"}
'|'
Returns: 2
{"//\\"," -\\"}
'\\'
Returns: 7
{"|/","|\\"}
'|'
Returns: 5
{"|-","\\\\","- "}
'/'
Returns: 8
{" -"," ","|/"}
'\\'
Returns: -1
{"--\\\\","\\- |"," \\ /"}
'-'
Returns: 14
{"\\"}
'|'
Returns: 1
{"|"}
'-'
Returns: 1
{"| |\\"," | \\"}
'-'
Returns: -1
{"|"," "}
'/'
Returns: 1
{"-"," ","/"}
'-'
Returns: -1
{"|\\|"}
'\\'
Returns: 5
{"\\"," "}
'-'
Returns: 1
{"//"," \\","/|"}
'\\'
Returns: 8
{"|-\\\\"}
'/'
Returns: 6
{"|","\\","|"}
'|'
Returns: 4
{"\\","/"}
'|'
Returns: 3
{"|"}
'-'
Returns: 1
{"/|--"}
'-'
Returns: 6
{"|"," "}
'/'
Returns: 1
{"| ||"}
'\\'
Returns: -1
{"-"," "}
'-'
Returns: 0
{"-","|"}
'/'
Returns: 3
{"/-","-|"}
'-'
Returns: 7
{"-"}
'-'
Returns: 0
{"-"}
'/'
Returns: 1
{" \\"}
'-'
Returns: -1
{"||","| "}
'-'
Returns: 4
{"|\\"}
'-'
Returns: 3
{"\\","-"," "}
'\\'
Returns: 2
{"-/\\","/ -","/\\\\"}
'\\'
Returns: 13
{"-\\|","\\\\\\"}
'/'
Returns: 9
{"-","|"}
'\\'
Returns: 3
{" --","|-|\\","\\ / "}
'|'
Returns: -1
{"/\\","/|","-|"}
'-'
Returns: 9
{"| "}
'\\'
Returns: 1
{"|"}
'\\'
Returns: 1
{"||//"}
'-'
Returns: 5
{"|"," ","-"}
'\\'
Returns: -1
{"\\-| "," -\\-","\\||-"}
'\\'
Returns: 16
{"/ ||","| \\-"," -|/"}
'-'
Returns: -1
{"/ ","\\ |/"}
'/'
Returns: -1
{"|/ ","||\\"}
'/'
Returns: 7
{"||-","\\/|"," | "}
'|'
Returns: 11
{"/ "," -","||"}
'/'
Returns: -1
{"-","\\"}
'|'
Returns: 3
{"-","-","|"}
'-'
Returns: 3
{"-","/"}
'|'
Returns: 3
{"||","/\\"}
'/'
Returns: 6
{"/- ", "/ ", "/--" }
'/'
Returns: 9
{"/-|/", "/ | ", "-/\\/" }
'-'
Returns: 17
{"/--/", "- -", "||| " }
'-'
Returns: 17
{"/-|/", "/ |/", "-/\\/" }
'\\'
Returns: 18
{"/-|/", "/ |/", "-/\\-" }
'\\'
Returns: 19
{"\\ \\-", "-- \\", "\\|| " }
'-'
Returns: -1
{"|- \\", "| /\\", "-//-" }
'/'
Returns: 17
{"|/-\\", "/-\\|", "-\\|/" }
'-'
Returns: 23
{"///", "///", "---" }
'-'
Returns: 10
{"\\ / ", "/-\\|", "- - " }
'-'
Returns: 17
{"///", "|||", " " }
'-'
Returns: 7
{" ||", "|||", "|||" }
'|'
Returns: -1