Intuit Interview Question
Senior Software Development EngineersCountry: United States
Interview Type: In-Person
Here is the code for you:
import java.util.Arrays;
/**
* Created by rajive.pai on 2/22/2017.
*/
public class FindIndex {
public static void main(String args[]){
Integer[] arr = {12,3,4,55,2,333,566};
System.out.println(index(arr , 333));
}
public static Integer index(Integer[] a, Integer n){
return Arrays.asList(a).indexOf(n);
}
}
Here is the code for you:
import java.util.Arrays;
/**
* Created by rajive.pai on 2/22/2017.
*/
public class FindIndex {
public static void main(String args[]){
Integer[] arr = {12,3,4,55,2,333,566};
System.out.println(index(arr , 333));
}
public static Integer index(Integer[] a, Integer n){
return Arrays.asList(a).indexOf(n);
}
}
Here is the code for you:
import java.util.Arrays;
/**
* Created by rajive.pai on 2/22/2017.
*/
public class FindIndex {
public static void main(String args[]){
Integer[] arr = {12,3,4,55,2,333,566};
System.out.println(index(arr , 333));
}
public static Integer index(Integer[] a, Integer n){
return Arrays.asList(a).indexOf(n);
}
}
public class IntArrayIndex {
public static void main(String[] args) {
int[] arr = { 20, 30, 40 };
// find index for 30
int returnVal = index(arr, arr.length, 30);
System.out.println(returnVal);
}
public static int index(int[] arr, int n, int value) {
if (arr[n - 1] == value) {
return n;
}
return index(arr, n - 1, value);
}
}
public class IntArrayIndex {
public static void main(String[] args) {
int[] arr = { 20, 30, 40 };
// find index for 30
int returnVal = index(arr, arr.length, 30);
System.out.println(returnVal);
}
public static int index(int[] arr, int n, int value) {
if (arr[n - 1] == value) {
return n;
}
return index(arr, n - 1, value);
}
}
public class IntArrayIndex {
public static void main(String[] args) {
int[] arr = { 20, 30, 40 };
// find index for 30
int returnVal = index(arr, arr.length, 30);
System.out.println(returnVal);
}
public static int index(int[] arr, int n, int value) {
if (arr[n - 1] == value) {
return n;
}
return index(arr, n - 1, value);
}
}
public class IntArrayIndex {
public static void main(String[] args) {
int[] arr = { 20, 30, 40 };
// find index for 30
int returnVal = index(arr, arr.length, 30);
System.out.println(returnVal);
}
public static int index(int[] arr, int n, int value) {
if (arr[n - 1] == value) {
return n;
}
return index(arr, n - 1, value);
}
}
public class IntArrayIndex {
public static void main(String[] args) {
int[] arr = { 20, 30, 40 };
// find index for 30
int returnVal = index(arr, arr.length, 30);
System.out.println(returnVal);
}
public static int index(int[] arr, int n, int value) {
if (arr[n - 1] == value) {
return n;
}
return index(arr, n - 1, value);
}
}
public class IntArrayIndex {
public static void main(String[] args) {
int[] arr = { 20, 30, 40 };
// find index for 30
int returnVal = index(arr, arr.length, 30);
System.out.println(returnVal);
}
public static int index(int[] arr, int n, int value) {
if (arr[n - 1] == value) {
return n;
}
return index(arr, n - 1, value);
}
}
Arrays.binarySearch(int[] a, int key);
- venkat2023 October 15, 2016Returns index if exists or -1 otherwise