MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / search

Method search

SearchingInArrayWhereElementsDifferByK.java:5–20  ·  view source on GitHub ↗
(int arr[], int n, int x, int k)

Source from the content-addressed store, hash-verified

3
4 // Function for finding maximum and value pair
5 public static int search (int arr[], int n, int x, int k) {
6 //Complete the function
7
8 int index=0;
9
10 while(index<n)
11 {
12 if(arr[index]==x) return index;
13
14 int steps = Math.abs(arr[index]-x)/k;
15
16 index= index + Math.max(1,steps);
17 }
18
19 return -1;
20 }
21}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected