Intro to Tutorial Challenges

Sort by

recency

|

397 Discussions

|

  • + 0 comments
    function introTutorial(V, arr) {
        return arr.findIndex(element => element === V);
    }
    
  • + 0 comments

    4000+ word question for an brainless answer: return arr.indexOf(V)

  • + 0 comments

    Here are my c++ solutions, you can watch the explanation here : https://youtu.be/teDaBhua0bc

    solution 1:

    int introTutorial(int V, vector<int> arr) {
        for(int i = 0; i < arr.size(); i++) if(arr[i] == V) return i;
        return 0;
    }
    

    solution 2:

    int introTutorial(int V, vector<int> arr) {
        return distance(arr.begin(), find(arr.begin(), arr.end(), V));
    }
    
  • + 0 comments

    The two-pointer approach reduces the number of iterations compared to a simple linear search.

        public static int introTutorial(int V, List<Integer> arr) {
        // Write your code here
            for (int i = 0, j = arr.size() - 1; i < j; i++, j--) {
                if (Objects.equals(arr.get(i), V)) {
                    return i;
                } 
                
                if (Objects.equals(arr.get(j), V)) {
                    return j;
                } 
            }
            
            return -1;
        }
    
  • + 0 comments

    My C code 😁😎

    int introTutorial(int V, int arr_count, int* arr) {
        int index = 0;
        while(arr[index] != V){
            index++;
        }
        return index;
    }