title: create a function that returns an array strings rearranged as a palindrome
body: <p>I am trying to write a function which takes as input an array of strings with only lower case letters. Function returns an array of same strings but with each string has its letter rearranged such that it becomes a palindrome if possible, and if not then it returns -1.  </p>
  
  <pre><code>public static Object buildPalin(String[] arrayOfStrings) 
  {
      String[] palindrome = new String[arrayOfStrings.length];
      int offset = 0; 
  
      int charWithoutReflection = 0; 
      List&lt;String&gt; whole= Arrays.asList(arrayOfStrings);
      String wholeString = String.join("", whole);
  
      for(int i=0; i&lt; arrayOfStrings.length; i++) 
      { 
          if (arrayOfStrings[i] != "") 
          { 
              int currentCharPosition = wholeString.indexOf(arrayOfStrings[i], 
              i + 1); 
  
              if (currentCharPosition != -1)
              { 
                  palindrome[offset] = arrayOfStrings[i]; 
                  palindrome[palindrome.length - 1 - offset] = 
                  arrayOfStrings[i]; 
                  arrayOfStrings[currentCharPosition] = ""; 
                  arrayOfStrings[i] = ""; 
              }
              else {
                  if (charWithoutReflection &gt; 0) 
                      return -1; 
                  palindrome[palindrome.length/2] = arrayOfStrings[i]; 
                  charWithoutReflection++; 
              }
              offset++; 
          }
      } 
      return palindrome;
     } 
  </code></pre>
  
  <p>This function works fine for case when input array is like this 
       {"a", "b", "a"}
       {"a","b","c"} and so on.</p>
  
  <p>but when i am having input like below:
       {"aba", "bb", "cac"} and like this that is array of strings it fails.</p>
  
  <p>Any guidance or suggestion on this is helpful.</p>
  
  <p>NOTE:
  This is not a class assignment but its a question i was asked in interview.
  I was able to come up with above solution but now i am trying to make it working for corner case as well. This will be helpful for future interviews. </p>
  
  <p>==============================Updated code as per comment of Eric below=========</p>
  
  <pre><code>public static Object build(String[] arrayOfStrings) {
     String[] palindrome = new String[arrayOfStrings.length];
     int offset = 0; 
     int charWithoutReflection = 0; 
     List&lt;String&gt; whole= Arrays.asList(arrayOfStrings);
     String wholeString = String.join("", whole);
  
     for(int i=0; i&lt; arrayOfStrings.length; i++) 
     { 
        if (arrayOfStrings[i] != "") { 
          int currentCharPosition = wholeString.indexOf(arrayOfStrings[i], i + 
          1); 
  
          if (currentCharPosition != -1)
          { 
            palindrome[offset] = arrayOfStrings[i]; 
            palindrome[palindrome.length - 1 - offset] = arrayOfStrings[i]; 
            arrayOfStrings[currentCharPosition] = ""; 
            arrayOfStrings[i] = ""; 
          }
          else {
            if (charWithoutReflection &gt; 0) 
            {
               System.out.println("failed case");
               return -1;
            }
            palindrome[palindrome.length/2] = arrayOfStrings[i]; 
            charWithoutReflection++; 
          }
          offset++; 
          }
      } 
      return palindrome;
    }
  
    // code from main function calling above function is:
    public static void main(String[] args) {
      String a[] = {"abb"};
      for ( int j = 0; j &lt; a.length ; j++)
      {
        String[] tokens = a[j].split("");
  
        System.out.println(Arrays.deepToString((Object[]) build(tokens)));    
  
      }
  </code></pre>
  
  <p>Produces wrong output as : ( for input [a,b,b]</p>
  
  <p>[null, b, null]  instead of [b, a, b] </p>