Problem: 2049B - pspspsps
Language: java

Solution 1 (runtime: 280 ms):
import java.util.HashSet;

import java.util.Scanner;



public class PSPS {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int testCase=sc.nextInt();

        while (testCase-- >0){

            int n=sc.nextInt();

            String s=sc.next();

            int pidx=s.indexOf('p');

            int sidx=s.lastIndexOf('s');

            HashSet<Character> hs=new HashSet<>();

            for (int i = 1; i < n-1; i++) {

                if(s.charAt(i)!='.') hs.add(s.charAt(i));

            }

            if(hs.size()>1 || (pidx<sidx && pidx!=-1)) System.out.println("NO");

            else System.out.println("YES");

        }

    }

}

Solution 2 (runtime: 218 ms):
import java.util.*;
import java.io.*;

public class Main {
	static InputStream inputStream;
	static OutputStream outputStream;
	static InputReader in;
	static PrintWriter out;
	static int MULTIPLE_TESTCASES = 1;
	static String PROB_NAME = "";

	///////////////////////////////////////
	// solution
	///////////////////////////////////////
	static class Solution {

		public void solve(int tc) throws IOException {
			int n = in.ni();
			char[] s = in.ns().toCharArray();
			int sc = 0;
			int pc = 0;
			int dc = 0;

			if (s[0] == '.')
				s[0] = 's';
			if (s[n - 1] == '.')
				s[n - 1] = 'p';
			for (int i = 0; i < n; ++i) {
				if (s[i] == 'p')
					++pc;
				else if (s[i] == 's')
					++sc;
				else
					++dc;
			}
			if (sc == 0 || pc == 0) {
				out.println("YES");
				return;
			}
			if (s[0] == 's' && pc + dc == n - 1) {
				out.println("YES");
				return;
			}
			if (s[n - 1] == 'p' && sc + dc == n - 1) {
				out.println("YES");
				return;
			}
			out.println("NO");
		}
	}

	private static void precompute() {

	}

	///////////////////////////////////////
	// template
	///////////////////////////////////////
	public static void main(String[] args) throws IOException {
		inputStream = System.in;
		outputStream = System.out;
		if (PROB_NAME != "") {
			inputStream = new FileInputStream(new File(PROB_NAME + ".in"));
			outputStream = new FileOutputStream(new File(PROB_NAME + ".out"));
		}
		in = new InputReader(inputStream);
		out = new PrintWriter(outputStream);
		int tc = 1;
		if (MULTIPLE_TESTCASES > 0)
			tc = in.ni();
		precompute();
		Solution sol = new Solution();
		for (int i = 1; i <= tc; ++i) {
			sol.solve(i);
		}
		in.close();
		out.close();
	}

	static class InputReader {
		BufferedReader reader;
		StringTokenizer st;

		public InputReader(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			st = null;
		}

		public String ns() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public Long nl() throws IOException {
			return Long.parseLong(ns());
		}

		public Integer ni() throws IOException {
			return Integer.parseInt(ns());
		}

		public int[] nia(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; ++i) {
				a[i] = ni();
			}
			return a;
		}

		public long[] nla(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; ++i) {
				a[i] = nl();
			}
			return a;
		}

		public void close() throws IOException {
			reader.close();
		}
	}
}