sibling search java program

Solutions on MaxInterview for sibling search java program by the best coders in the world

showing results for - "sibling search java program"
Sofie
15 Jan 2017
1  public int[] getSiblings(int[] arr, int x) {
2    int pos = 0;
3    for (int i = 0; i < arr.length; i++) {
4      if(arr[i]==x) pos = i+1;
5    }
6    int start = Integer.highestOneBit(pos); // get max power of 2
7    int end = start*2-1 >= arr.length ? arr.length: start*2-1;
8    return IntStream.range(start-1, end).map(i -> arr[i]).filter(v -> v!=x).toArray();
9  }
10
similar questions
queries leading to this page
sibling search java program