Paypal 1st Round of Interview

I was applying for SSE Android Role in Paypal.
The first round was a simple DSA Round.

Palindromic Algorithms

Description
A word-generating system is currently being trained on palindromic algorithms. A string that consists of lowercase English characters is said to be a palindrome if it reads the same forward and backward. For example, "a", "abbcbba" are palindromes whereas "hackerrank", "cdec" are not.
For a given string s, the algorithm can change any number of characters in the string and permute the resulting string in any desired order. The algorithm aims to produce a palindrome after the fewest possible character changes. If there are multiple possible palindromes after the fewest number of changes, return the lexicographically smallest of them.
Note: A string a is lexicographically smaller than another string b of the same length if the first different letter from the left in a and b is smaller in a.

Example
Consider the string s = "azzzbbb".
Optimally, the algorithm changes one 'z' to 'a'. The resulting string is "aazzbbb". This can be permuted to form "abzbzba", which is the lexicographically minimum palindromic string possible after 1 change. So, the answer is "abzbzba".

Note that multiple palindromes are possible after 1 substitution. For example, after substituting
'a' for 'z' as shown, palindromic permutations 'azbbbza' and 'zabbbaz' can be formed. Also, 'a' might be replaced with 'Z' and the string rearranged to form a palindrome, "zzbbbzz". These are all lexicographically larger than the optimal solution.

Function Description
Complete the function makeLexicographicallySmallestPalindrome in the editor below.
makeLexicographicallySmallestPalindrome has the following parameter:
strings: the given string

Returns
string. the lexicographically smallest palindromic string that can be obtained by changing a minimum number of characters
Constraints
• 1 ≤ 15| ≤ 3 * 105
• The strings consists of lowercase English characters only.
image

Below is the code where you have to implement.


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;


class Result {

    /*
     * Complete the 'makeLexicographicallySmallestPalindrome' function below.
     *
     * The function is expected to return a STRING.
     * The function accepts STRING s as parameter.
     */

    public static boolean makeLexicographicallySmallestPalindrome(String s) {
        return true;
    }
    
    public static String makePalindrome(String s) {
        return s;
    }
}


public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        String s = bufferedReader.readLine();

        // String result = Result.makeLexicographicallySmallestPalindrome(s);

        if(Result.makeLexicographicallySmallestPalindrome(s)) {
            
        } else {
            Result.makePalindrome(s);
        }
        bufferedWriter.write(s);
        bufferedWriter.newLine();

        bufferedReader.close();
        bufferedWriter.close();
    }
}

Please feel free to review the second round of the interview.

Comments (3)