Special Elements
Given a matrix of integers, task is to find out number of special elements. A special element is one which is either minimum or maximum in a row or in a column. Return -1 if any row or any column has multiple minimum or maximum elements.
Input : [ [1, 3, 4], [5, 2, 9], [8, 7, 6] ]
Output : 7
Coding Wars
There are N coders standing in a line, where i denotes the ith position of a coder with Rating of Ri. All ratings are distinct. You have to form a team of 3 from amongst them with condition :
"Any three coders with positions (i, j, k) and ratings (Ri, Rj, Rk) can form a team when ( "Ri<Rj<Rk" or "Ri>Rj>Rk" ) and ( 1 <= i < j < k <= N ) "
You have to find out how many such teams exists ( 1 coder can be part of multiple teams ).
Input :
N = 5
Ratings = [ 5, 2, 3, 1, 4 ]
Output :
3
Hint : [ 5, 2, 1 ] [ 5, 3, 1 ] [ 2, 3, 4 ]