Find and print the element at the mid index array ignoring all the indices at which negative numbers are present in the array.
Find and print the element at the mid index array ignoring all the indices at which negative numbers are present in the array.

Find and print the element at the mid index array ignoring all the indices at which negative numbers are present in the array.

You are given an array arr of length n. Find and print the element at the mid index array ignoring all the indices at which negative numbers are present in the array.

Note : In case there are two mid indices, print the element at the smaller index. You may assume that there will be at least one positive integer in array.

You are given an array of integers. The task is to find and print the element located at the middle index of the array, but you need to ignore any elements at indices where the value is negative(-).

Find and print the element at the mid index array ignoring all the indices at which negative numbers are present in the array.

3 Basic Steps to Understand the Problem on mid index array ignoring all the indices at which negative numbers are present in the array.

  1. Array Filtering: The array might contain negative(-) numbers, but they should be ignored when determining the “middle” element of the array.
  2. Middle Element: The “middle” element is defined as the element at the index len(filtered_array) // 2 of a new array containing only the whole number elements of the original array.
  3. Output: Once the middle element is determined from the filtered array, it will be printed or returned.

ACCENTURE INTERVIEW CODING QUESTION 2024 | 16th AUG

We have coded this Ques for you Javascript, Java, Python, & C++:

In Python

Array Definition: The array arr is defined directly.
Filtering: List comprehension is used to filter out non-negative(whole numbers) elements.
Middle Index Calculation: The middle index is calculated using integer division (//).
Output: The element at the middle index is printed using print().

In Java

Array Definition: The array arr is defined inside the main method().
Filtering: Non-negative elements are stored in an ArrayList.
Middle Index Calculation: The middle index is calculated using integer division.
Result: The element at the middle index is printed using System.out.println()

ACCENTURE INTERVIEW CODING QUESTION 2024 | 20th AUG

In Javascript

Array Definition: The array arr is directly defined in the script with a mix of positive and negative integers.
Filtering: The filter() method creates a new array filteredArr containing only non-negative numbers.
Middle Index Calculation: The middle index of filteredArr is computed using integer division with Math.floor() to ensure it’s an integer.
Result: The element at the middle index of filteredArr is printed to the console using console.log().

APPLY ON INFOSYS: Click Here

In C++

Array Definition: The array arr is defined as a std::vector<int>.
Filtering: Non-negative elements(whole number elements) are added to a std::vector<int>.
Middle Index Calculation: The middle index is calculated using integer division.
Output: The element at the middle index is printed using std::cout.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *