#74 Finding an Element Index in an Array

Companies:
OTP Bank
Themes:
JavaJava BasicsPractice

An int[] nums array is given. Write a method that finds the index of an element in the array:

public class Main {
    public static void main(String[] args) {
        int[] nums = {10, 20, 30, 40, 50};
        int target = 30;
        int index = findIndex(nums, target);

        System.out.println("Index of " + target + " is: " + index);
    }

    public static int findIndex(int[] nums, int target) {
        ...
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in