<p>On an alphabet board, we start at position <code>(0, 0)</code>, corresponding to character&nbsp;<code>board[0][0]</code>.</p>

<p>Here, <code>board = [&quot;abcde&quot;, &quot;fghij&quot;, &quot;klmno&quot;, &quot;pqrst&quot;, &quot;uvwxy&quot;, &quot;z&quot;]</code>, as shown in the diagram below.</p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2019/07/28/azboard.png" style="width: 250px; height: 317px;" /></p>

<p>We may make the following moves:</p>

<ul>
	<li><code>&#39;U&#39;</code> moves our position up one row, if the position exists on the board;</li>
	<li><code>&#39;D&#39;</code> moves our position down one row, if the position exists on the board;</li>
	<li><code>&#39;L&#39;</code> moves our position left one column, if the position exists on the board;</li>
	<li><code>&#39;R&#39;</code> moves our position right one column, if the position exists on the board;</li>
	<li><code>&#39;!&#39;</code>&nbsp;adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code>&nbsp;to the&nbsp;answer.</li>
</ul>

<p>(Here, the only positions that exist on the board are positions with letters on them.)</p>

<p>Return a sequence of moves that makes our answer equal to <code>target</code>&nbsp;in the minimum number of moves.&nbsp; You may return any path that does so.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> target = "leet"
<strong>Output:</strong> "DDR!UURRR!!DDD!"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> target = "code"
<strong>Output:</strong> "RR!DDRR!UUL!R!"
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= target.length &lt;= 100</code></li>
	<li><code>target</code> consists only of English lowercase letters.</li>
</ul>
class Solution {
public:
    int rowNumber(char s)
    {
        if (s == 'a' || s=='b'|| s=='c' || s=='d' || s=='e')
            return 0;
        if (s == 'f' || s=='g'|| s=='h' || s=='i' || s=='j')
            return 1;
        if (s == 'k' || s=='l'|| s=='m' || s=='n' || s=='o')
            return 2;
        if (s == 'p' || s=='q'|| s=='r' || s=='s' || s=='t')
            return 3;
        
        return 4;
        
    }
    int colNumber(char s)
    {
        if (s == 'a' || s=='f'|| s=='k' || s=='p' || s=='u' || s=='z')
            return 0;
        if (s == 'b' || s=='g'|| s=='l' || s=='q' || s=='v')
            return 1;
        if (s == 'c' || s=='h'|| s=='m' || s=='r' || s=='w')
            return 2;
        if (s == 'd' || s=='i'|| s=='n' || s=='s' || s=='x')
            return 3;
        return 4;
    }
    string iteratePush(char action, int count)
    {
        string temp="";
        for (int i=0; i<count; i++)
        {
            temp+=action;
        }
        return temp;
    }
    string alphabetBoardPath(string target) {
        int startRow =0;
        int startCol=0;
        string result="";
        for (int i=0; i<target.length(); i++)
        {
            if(target[i]=='z')
            {
                if (startCol !=0)
                {
                    int row = 4;
                    result = result + iteratePush('D', row-startRow);
                    int col = 0;
                    result = result + iteratePush('L', startCol - col);
                    result = result + 'D';
                }
                else result = result + iteratePush('D', 5-startRow);
               
                startCol = 0;
                startRow = 5;
            }
            else
            {
                if (startCol==0 &&startRow==5)
                {
                     result = result + 'U';
                     startRow = 4;
                }
                   
                int row = rowNumber(target[i]);
                if (startRow -row <0)
                {
                    result = result + iteratePush('D',row-startRow);
                }
                else if (startRow - row>0)
                {
                    result =result+ iteratePush('U',startRow-row);
                    
                }
                startRow = row;
                int col = colNumber(target[i]);
                if (startCol - col<0)
                {
                    result = result + iteratePush('R', col-startCol);
                }
                else if(startCol - col>0)
                {
                    result = result + iteratePush('L', startCol - col);
                }
                startCol = col;
               
            }
            result = result + '!';
            

        }
        return result;
    }
};
9100