title: Love letter String rotation company test programming question base testcase passed, hidden testcase failing
body: <p>I Gave a test on platform named mettl for hiring of a company.</p>
  <p><strong>Problem statement :</strong></p>
  <p>You write a love letter to you friend. However, before your friend can read it, someone else read it and rotates the characters of each word to the right K times. Find the number of words that remain the same even after this shifting of letters.</p>
  <p><strong>Note:</strong> There can be more than one spaces between the words.</p>
  <p><strong>Input specifications:</strong></p>
  <p>Input1: String of words</p>
  <p>Input2: K number of times rotation happens</p>
  <p><strong>Output specifications:</strong></p>
  <p>Your function should return the numbers of correct words.</p>
  <p><strong>Example 1:</strong></p>
  <p><strong>Input1:</strong> llohe ereth</p>
  <p><strong>Input 2:</strong> 2</p>
  <p><strong>Output:</strong> 0</p>
  <p><strong>Explanation:</strong> In example 1, &quot;llohe ereth&quot; is a rotated string with K factor 2. Hence after moving the last two letters of right to left , we get the original string as &quot;Hello there&quot;.</p>
  <p><strong>Example 2:</strong></p>
  <p><strong>Input1:</strong> adaada</p>
  <p><strong>Input 2:</strong> 3</p>
  <p><strong>Output:</strong> 1</p>
  <p><strong>Explanation:</strong> In example 2, &quot;adaada&quot; when rotated 3 times gives back &quot;adaada&quot;. Hence answer is 1.</p>
  <p>I wrote below Solution which passed the above 2 base cases, but was failing for hidden testcases (also includes time complexity testcase). Only one corner testcase passed because I was checking String input1 not to be empty. Solution is as below:</p>
  <pre><code>public int rotatedWords(String input1, int input2) {
      int count = 0;
      String arr[] = input1.split(&quot; &quot;);
      if (input1 != null &amp;&amp; !input1.isEmpty()) {
          for (int i = 0; i &lt; arr.length; i++) {
              String s1 = arr[i] + arr[i];
              int start = arr[i].length() - input2;
  
              System.out.println(&quot;arr[i] : &quot; + arr[i]);
              String s2 = s1.substring(start, start + arr[i].length());
              System.out.println(&quot;s2 : &quot; + s2);
              if (s2.equalsIgnoreCase(arr[i])) {
                  count++;
              }
          }
      }
      return count;
  }
  </code></pre>
  <p>Ask is that , I wasn't able to understand why the hidden testcases were failing. Please help me.</p>