2
public int[] executeInstructions(int n, int[] startPos, String s) {3
// Make array of length equal to string length4
int ans[] = new int[s.length()];6
// Now use two for loops7
for (int i = 0; i < s.length(); i++) {8
// countmoves will keep on counting the valid moves from i to s.length10
int yIndex = startPos[0];11
int xIndex = startPos[1];12
for (int j = i; j < s.length(); j++) {14
if (s.charAt(j) == 'R') {17
if (s.charAt(j) == 'L') {20
if (s.charAt(j) == 'U') {23
if (s.charAt(j) == 'D') {26
if (xIndex < 0 || xIndex >= n || yIndex < 0 || yIndex >= n) {