You are given an array A of size N. The task is to find count of elements before which all the elements are smaller. First element is always counted as there is no other element before it.
 
Example 1:
Input : 
arr[] =  {10, 40, 23, 35, 50, 7}
Output : 
3
Explanation :
The elements are 10, 40 and 50.
No of elements is 3
 
Example 2:
Input : 
arr[] = {5, 4, 1}
Output : 
1
Explanation :
There is only one element 5
No of element is 1
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function countElements() which takes the array arr[] and its size N as inputs and returns the Number of Elements before which no element is bigger.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{5}
1 ≤ A_{i} ≤ 10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

class Solution:
    def countElements(self, arr, n):
        # Your code goes here

Solutions:
class Solution:

	def countElements(self, arr, n):
		cnt = 1
		m = arr[0]
		for i in range(1, n):
			if m < arr[i]:
				m = arr[i]
				cnt += 1
		return cnt


class Solution:

	def countElements(self, arr, n):
		c = 1
		maxx = arr[0]
		for i in arr[1:]:
			if i > maxx:
				c += 1
				maxx = i
		return c


class Solution:

	def countElements(self, arr, n):
		count = 0
		curr = 0
		cash = set()
		for i in range(arr.index(max(arr)) + 1):
			if arr[i] >= curr and arr[i] not in cash:
				count += 1
				cash.add(arr[i])
				curr = arr[i]
		return count


class Solution:

	def countElements(self, arr, n):
		c = 1
		a = arr[0]
		if n > 1:
			for i in range(n):
				if a < arr[i]:
					c += 1
					a = arr[i]
		return c


class Solution:

	def countElements(self, arr, n):
		count = 1
		max_so_far = arr[0]
		for i in range(1, len(arr)):
			if arr[i] > max_so_far:
				max_so_far = arr[i]
				count += 1
		return count


class Solution:

	def countElements(self, arr, n):
		count = 1
		maxs = arr[0]
		for i in range(1, n):
			if maxs < arr[i]:
				maxs = arr[i]
				count += 1
		return count


class Solution:

	def countElements(self, arr, n):
		count = 1
		top = arr[0]
		for i in range(1, n):
			if top < arr[i]:
				count += 1
				top = max(top, arr[i])
		return count


class Solution:

	def countElements(self, arr, n):
		count = []
		count.append(arr[0])
		max_ele = arr[0]
		for i in range(1, n, 1):
			if arr[i] > max_ele:
				count.append(arr[i])
				max_ele = max(max_ele, arr[i])
		return len(count)


class Solution:

	def countElements(self, arr, n):
		count = 1
		maximum = arr[0]
		for ele in arr[1:]:
			if ele > maximum:
				count += 1
				maximum = ele
		return count


class Solution:

	def countElements(self, arr, n):
		res = 0
		max_val = -9999
		for i in arr:
			if i > max_val:
				res += 1
				max_val = i
		return res


class Solution:

	def countElements(self, arr, n):
		c = 0
		lar = -100000000.0
		for i in range(n):
			if arr[i] > lar:
				c += 1
				lar = arr[i]
		return c


class Solution:

	def countElements(self, arr, n):
		cm = arr[0]
		count = 1
		for elem in arr:
			if elem > cm:
				cm = elem
				count += 1
		return count


class Solution:

	def countElements(self, arr, n):
		max = -1
		count = 0
		for item in arr:
			if item > max:
				max = item
				count += 1
		return count


class Solution:

	def countElements(self, arr, n):
		x = arr[0]
		count = 1
		b = 1
		while b < n:
			if arr[b] > x:
				count += 1
				x = arr[b]
				b += 1
			else:
				b += 1
		return count


class Solution:

	def countElements(self, arr, n):
		c = 0
		mx = -100000
		for x in arr:
			if mx < x:
				c += 1
				mx = x
		return c


class Solution:

	def countElements(self, arr, n):
		s = 1
		m = arr[0]
		for j in range(1, n):
			if arr[j] > m:
				s = s + 1
				m = arr[j]
		return s


class Solution:

	def countElements(self, arr, n):
		count = 0
		val = -9999999999
		for i in range(n):
			if arr[i] > val:
				val = arr[i]
				count += 1
		return count


class Solution:

	def countElements(self, arr, n):
		stack = [arr[0]]
		for item in arr[1:]:
			if item > stack[-1]:
				stack.append(item)
		return len(stack)


class Solution:

	def countElements(self, arr, n):
		ans = 1
		comp = arr[0]
		for i in range(1, n):
			if comp < arr[i]:
				comp = arr[i]
				ans += 1
		return ans


class Solution:

	def countElements(self, arr, n):
		maxx = float('-inf')
		cnt = 0
		for i in range(n):
			if arr[i] > maxx:
				maxx = arr[i]
				cnt += 1
		return cnt


class Solution:

	def countElements(self, arr, n):
		s = []
		mx = 0
		for i in range(n):
			mx = max(mx, arr[i])
			s.append(mx)
		s = set(s)
		return len(s)


class Solution:

	def countElements(self, arr, n):
		count = 0
		while len(arr) > 1:
			m = max(arr)
			ind1 = arr.index(m)
			if ind1 != 0:
				count += 1
			del arr[ind1:]
		return count + 1


class Solution:

	def countElements(self, arr, n):
		t = arr[0]
		c = 0
		for i in range(1, len(arr)):
			if arr[i] > t:
				c += 1
				t = arr[i]
		return c + 1


class Solution:

	def countElements(self, arr, n):
		ans = 1
		current = arr[0]
		for i in arr[1:]:
			if i > current:
				ans += 1
			current = max(current, i)
		return ans


class Solution:

	def countElements(self, arr, n):
		res = 1
		maxno = arr[0]
		for i in range(n):
			if arr[i] > maxno:
				res += 1
				maxno = arr[i]
		return res


class Solution:

	def countElements(self, arr, n):
		maxx = arr[0]
		count = 1
		for i in arr:
			if i > maxx:
				maxx = max(i, maxx)
				count += 1
		return count


class Solution:

	def countElements(self, arr, n):
		maxx = -float('inf')
		counter = 0
		for i in arr:
			if i > maxx:
				maxx = max(i, maxx)
				counter += 1
		return counter


class Solution:

	def countElements(self, arr, n):
		m = -float('inf')
		c = 0
		for i in arr:
			if i > m:
				m = max(i, m)
				c += 1
		return c


class Solution:

	def countElements(self, arr, n):
		result = 1
		max_ele = arr[0]
		for i in range(1, n):
			if arr[i] > max_ele:
				max_ele = arr[i]
				result += 1
		return result


class Solution:

	def countElements(self, arr, n):
		d = 1
		temp = arr[0]
		for ele in arr:
			if ele > temp:
				d += 1
				temp = ele
		return d


class Solution:

	def countElements(self, arr, n):
		count = 0
		m = -1
		for x in range(n):
			if arr[x] > m:
				count += 1
				m = arr[x]
		return count


class Solution:

	def countElements(self, arr, n):
		maxx = -float('inf')
		counter = 0
		for i in arr:
			if i > maxx:
				maxx = max(i, maxx)
				counter += 1
		return counter

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.countElements(a, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def countElements(self, arr, n):
		d = -99999999
		c = 0
		for i in arr:
			if i > d:
				c += 1
				d = i
		return c

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.countElements(a, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def countElements(self, a, n):
		lst = a[0]
		c = 1
		for i in range(n):
			if a[i] > lst:
				lst = a[i]
				c += 1
		return c

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.countElements(a, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def countElements(self, arr, n):
		count = 1
		maxNum = arr[0]
		for itr in range(1, n):
			if arr[itr] > maxNum:
				maxNum = arr[itr]
				count += 1
		return count

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.countElements(a, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def countElements(self, arr, n):
		count = 1
		min = arr[0]
		max = arr[0]
		for i in range(1, n):
			if arr[i] > min and arr[i] > max:
				count += 1
				max = arr[i]
		return count

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.countElements(a, n))
		T -= 1
if __name__ == '__main__':
	main()


import sys

class Solution:

	def countElements(self, arr, n):
		count = 0
		m = -sys.maxsize
		for i in range(n):
			if arr[i] > m:
				m = arr[i]
				count += 1
		return count


class Solution:

	def countElements(self, arr, n):
		k = 0
		for i in range(n):
			m = arr.index(max(arr))
			if m == 0:
				k += 1
				break
			elif m == 1:
				k += 2
				break
			else:
				k += 1
				arr = arr[0:m]
		return k


class Solution:

	def countElements(self, arr, n):
		maxi = float('-inf')
		count = 0
		for i in arr:
			if i > maxi:
				count += 1
				maxi = i
		return count