Java code

Java code posted
created at 18 Jul 15:13

Edit | Back
1
2
3
4
5
6
7
8
9
  private static boolean[] buildRandomBalancedWord(int n) {
    boolean[] word = new boolean[n * 2];
    List<Integer> positions = IntStream.range(0, 2 * n).boxed().collect(Collectors.toList());
    for (int i = n; i > 0; i--) {
      int index = random.nextInt(n + i);
      word[positions.remove(index)] = true;
    }
    return word;
  }
330 Bytes in 8 ms with coderay