You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>A message containing letters from <code>A-Z</code> can be <strong>encoded</strong> into numbers using the following mapping:</p>
77272
+
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p>
77273
77273
77274
-
<pre>
77275
-
'A' -> "1"
77276
-
'B' -> "2"
77277
-
...
77278
-
'Z' -> "26"
77279
-
</pre>
77274
+
<p><code>"1" -> 'A'<br />
77275
+
"2" -> 'B'<br />
77276
+
...<br />
77277
+
"25" -> 'Y'<br />
77278
+
"26" -> 'Z'</code></p>
77280
77279
77281
-
<p>To <strong>decode</strong> an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, <code>"11106"</code> can be mapped into:</p>
77280
+
<p>However, while decoding the message, you realize that there are many different ways you can decode the message because some codes are contained in other codes (<code>"2"</code> and <code>"5"</code> vs <code>"25"</code>).</p>
77281
+
77282
+
<p>For example, <code>"11106"</code> can be decoded into:</p>
77282
77283
77283
77284
<ul>
77284
-
<li><code>"AAJF"</code> with the grouping <code>(1 1 10 6)</code></li>
77285
-
<li><code>"KJF"</code> with the grouping <code>(11 10 6)</code></li>
77285
+
<li><code>"AAJF"</code> with the grouping <code>(1, 1, 10, 6)</code></li>
77286
+
<li><code>"KJF"</code> with the grouping <code>(11, 10, 6)</code></li>
77287
+
<li>The grouping <code>(1, 11, 06)</code> is invalid because <code>"06"</code> is not a valid code (only <code>"6"</code> is valid).</li>
77286
77288
</ul>
77287
77289
77288
-
<p>Note that the grouping <code>(1 11 06)</code> is invalid because <code>"06"</code> cannot be mapped into <code>'F'</code> since <code>"6"</code> is different from <code>"06"</code>.</p>
77289
-
77290
-
<p>Given a string <code>s</code> containing only digits, return <em>the <strong>number</strong> of ways to <strong>decode</strong> it</em>.</p>
77290
+
<p>Note: there may be strings that are impossible to decode.<br />
77291
+
<br />
77292
+
Given a string s containing only digits, return the <strong>number of ways</strong> to <strong>decode</strong> it. If the entire string cannot be decoded in any valid way, return <code>0</code>.</p>
77291
77293
77292
77294
<p>The test cases are generated so that the answer fits in a <strong>32-bit</strong> integer.</p>
<strong>Explanation:</strong> "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").
<p>"06" cannot be mapped to "F" because of the leading zero ("6" is different from "06"). In this case, the string is not a valid encoding, so return 0.</p>
<p>On an <code>8 x 8</code> chessboard, there is <strong>exactly one</strong> white rook <code>'R'</code> and some number of white bishops <code>'B'</code>, black pawns <code>'p'</code>, and empty squares <code>'.'</code>.</p>
77278
+
<p>You are given an <code>8 x 8</code> <strong>matrix</strong> representing a chessboard. There is <strong>exactly one</strong> white rook represented by <code>'R'</code>, some number of white bishops <code>'B'</code>, and some number of black pawns <code>'p'</code>. Empty squares are represented by <code>'.'</code>.</p>
77279
77279
77280
-
<p>When the rook moves, it chooses one of four cardinal directions (north, east, south, or west), then moves in that direction until it chooses to stop, reaches the edge of the board, captures a black pawn, or is blocked by a white bishop. A rook is considered <strong>attacking</strong> a pawn if the rook can capture the pawn on the rook's turn. The <strong>number of available captures</strong> for the white rook is the number of pawns that the rook is <strong>attacking</strong>.</p>
77280
+
<p>A rook can move any number of squares horizontally or vertically (up, down, left, right) until it reaches another piece <em>or</em> the edge of the board. A rook is <strong>attacking</strong> a pawn if it can move to the pawn's square in one move.</p>
77281
77281
77282
-
<p>Return <em>the <strong>number of available captures</strong> for the white rook</em>.</p>
77282
+
<p>Note: A rook cannot move through other pieces, such as bishops or pawns. This means a rook cannot attack a pawn if there is another piece blocking the path.</p>
77283
+
77284
+
<p>Return the <strong>number of pawns</strong> the white rook is <strong>attacking</strong>.</p>
0 commit comments