title: How to replace question mark from a String so that same letter does not occur next to each other?
body: <p>I wrote the code below to replace each question mark from a String so that same letter does not occur next to each other. For example:</p>
  
  <p>Input</p>
  
  <pre><code>ab?ac?
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>abcaca
  </code></pre>
  
  <p>Please note that <code>?</code> should be replaced by any lowercase letter: <code>[a-z]</code></p>
  
  <p>Below is my solution. But my question: is there any more optimized way to solve this?</p>
  
  <pre><code>public String solution(String riddle) {
      char alpha[] = "abcdefghijklmnopqrstuvwxyz".toCharArray();
      if (riddle == null || riddle.indexOf('?') == -1) {
          return riddle;
      }
      StringBuilder sb = new StringBuilder("");
      int cnt = 0;
      for (int i = 0; i &lt; riddle.length(); i++) {
          char current = riddle.charAt(i);
          char prev = '\0';
          char next = '\0';
          if (current == '?') {
              current = alpha[cnt];
              if (i != 0) {
                  prev = sb.toString().charAt(i - 1);
              }
              if (i != riddle.length() - 1) {
                  next = riddle.charAt(i + 1);
              }
              while (current == prev || current == next) {
                  current = alpha[++cnt];
                  if (cnt % 25 == 0) {
                      cnt = 0;
                  }
              }
              sb.append(current);
          } else {
              sb.append(current);
          }
      }
      return sb.toString();
  }
  </code></pre>