Relative Content

Tag Archive for arraysalgorithmsearch

Should we really condition the lastIndex based on whenever array.length is odd or even in isMajority challenge?

Here are the details of the problem:
Given an array arr of N elements, A majority element in an array arr of size N is an element that appears more than N/2 times in the array. The task is to write a function say isMajority() that takes an array (arr[] ), array’s size (n) and a number to be searched (x) as parameters and returns true if x is a majority element (present more than n/2 times).
The solution states that the lastIndex in the loop should be conditioned.