minimum and maximum element in an array

Solutions on MaxInterview for minimum and maximum element in an array by the best coders in the world

showing results for - "minimum and maximum element in an array"
Suzanne
18 Oct 2017
1#include <bits/stdc++.h> 
2using namespace std;
3
4int main(){
5  	const int size = 10;
6  	int k = 3; //Can be any number smalled than size
7	int array[size] = {5,2,8,34,73,82,1,6,19,29};
8	sort(array,array+size);
9	int smallestKthElement = array[k-1];	
10	int largestKthElement = array[size-k];
11}
Laly
24 Nov 2018
1def divideAndConquer_Max(arr, ind, len):
2	maximum = -1;
3
4	if (ind >= len - 2):
5		if (arr[ind] > arr[ind + 1]):
6			return arr[ind];
7		else:
8			return arr[ind + 1];
9
10
11	maximum = divideAndConquer_Max(arr, ind + 1, len);
12
13	if (arr[ind] > maximum):
14		return arr[ind];
15	else:
16		return maximum;
17
18
19def divideAndConquer_Min(arr, ind, len):
20	minimum = 0;
21	if (ind >= len - 2):
22		if (arr[ind] < arr[ind + 1]):
23			return arr[ind];
24		else:
25			return arr[ind + 1];
26
27	minimum = divideAndConquer_Min(arr, ind + 1, len);
28
29	if (arr[ind] < minimum):
30		return arr[ind];
31	else:
32		return minimum;
33
34
35if __name__ == '__main__':
36
37	minimum, maximum = 0, -1;
38
39	# array initialization
40	arr = [6, 4, 8, 90, 12, 56, 7, 1, 63];
41
42	maximum = divideAndConquer_Max(arr, 0, 9);
43	minimum = divideAndConquer_Min(arr, 0, 9);
44
45	print("The minimum number in the array is: ", minimum);
46	print("The maximum number in the array is: ", maximum);
queries leading to this page
how to find minimum element in an arraymaximum and minimum of an arrayfind minimum and maximum valuehow can i find the maximum minimum from a array 3ffind maximum and second max element in arrayfind the minimum and maximum element in an arrafind the min and max elems of the arrayfind the 22kth 22 max and min element of an arrayfind minimum number in array using min and max functionmaximum and minimum of an array using minimum numberhow to define maximum and minimum value of an arrayfind the kth max and min element of an array practicewrite a program to find min and max element in an arrayhow to find minimum in arrayfind the kth minimum and maximum in an arrayminimum and maximum of a functionmaximum and minimum values of arrayhow to find minimum value of arrayfind the kth max and min element of an arrayfunction that finds and returns the minimum value in an array maximum and minimum element in an arrayfind the minimum and maximum element from the arrayminimum number of steps to get the maximum score of the arrayfind maximum and minumum arrayfind maximum and minimum number arrayfind the minimum number in an arrayminimum and maximum value of a functionfind minimum element in arrayfind the kth max and min element of an array pythonfind the k th max 2fmin in an arraywrite a program to find the maximum and minimum value of an arrayfind minimum and maximum element in an array in javamaximum value and minimum valuefind the minimum and maximum in an arrayhow to find the minimum element in an arrayfind maximum and minimum element in an arrayfind out the maximum and minimumfrom an arrayalgorithm to find maximum and minimum number in an arraykth max and min element in arraywhat is the minimum possible maximum element in a 3fwhat are the maximum and minimum values of a functionfind maximum and minimum element in an array gfgfind the minimum and maximum element in an arrayhow can i find the maximum minimum from an array 3ffind kth minimum value in arraycalculate the minimum element in the arrayfind minimum and maximum element in an array without using inbuilt functionsminimum time to find maximum element in arrayfunction that takes an array of numbers and return both the minimum and maximum numbers 2c in that order find the kth maximum and minimum element in an arrayhow to find maximum and minimum element in two arraysfind minimum number in array using min and maxminimum and maximum element in an array in onmaximum and minimum element in the given arraymaximum and minimum of array elementsfind the minimum and maximum element in an array minimum and maximum e element in an arrayfind minimum and maximum element in an arrayfind minimum value in arraymaximum minimum element in arrayk th min max element in arraymaximum and minimum elements in an arrayfinding minimum value in an array minimum and maximum element in an array hackerrankfinding minimum value in array of arrayshow to find the k maximum element in an arrayfind maximum and of k elements in an arrayfind kth max and min element in an arraykth max min element in arrayfind kth max and min element in an array practicemaximum and minimum in an arrayfind out minimum and maximum numbers in an arrayminimum and maximum element in an arrayfind kth min max arrayhow to find the minimum and maximum of a functionhow to find the minimum and maximum number of a arraymaximum and minimum element in the given array by comparisonskth max and min element in array bestfind maximum and minimum value of functionkth max element in arraygetting minimum and maximum value of a functionfind the maximum and minimum element in an arrayfind max and min value in array algorithmminimum and maximum element in an array