diff --git a/Array_Functions/Min_Max_Functions/min_max.cpp b/Array_Functions/Min_Max_Functions/min_max.cpp new file mode 100644 index 0000000..bfd95ca --- /dev/null +++ b/Array_Functions/Min_Max_Functions/min_max.cpp @@ -0,0 +1,45 @@ +# include +# include +using namespace std; + +vector max_ind(int arr[],int n){ + vector mx_ind_v; + int mx_ind=0; //initializing the index with the max value as 0 + for(int i=0; iarr[mx_ind]){ + mx_ind=i; + mx_ind_v.clear(); + mx_ind_v.push_back(mx_ind); //updating the max index + } + else if(arr[i]==arr[mx_ind]){ + mx_ind_v.push_back(i); //handling edge cases in case of multiple max indexes + } + } + return mx_ind_v; +} +vector min_ind(int arr[], int n){ + vector mn_ind_v={}; + int mn_ind=0; //initialising the index with the minimum value as 0 + for(int i=0; i a = max_ind(k,n); + vector b = min_ind(k,n); + return 0; + +} \ No newline at end of file diff --git a/Array_Functions/Min_Max_Functions/min_max.java b/Array_Functions/Min_Max_Functions/min_max.java new file mode 100644 index 0000000..984a0af --- /dev/null +++ b/Array_Functions/Min_Max_Functions/min_max.java @@ -0,0 +1,42 @@ +import java.util.ArrayList; + +public class min_max { + public static ArrayList max_ind( int [] arr){ + int mx_ind = 0; //initializing the index with the max value as 0 + ArrayList mx_ind_arr = new ArrayList<>(); + for(int i = 0; i< arr.length; i++){ + if(arr[i]> arr[mx_ind]){ + mx_ind=i; //updating the max index + mx_ind_arr.clear(); + mx_ind_arr.add(i); + } + else if( arr[mx_ind]== arr[i]){ + mx_ind_arr.add(i); //handling edge cases in case of multiple max indexes + } + } + return mx_ind_arr; + } + + public static ArrayList min_ind( int [] arr){ + int mn_ind = 0; //initialising the index with the minimum value as 0 + ArrayList mn_ind_arr = new ArrayList<>(); + for(int i = 0; i< arr.length; i++){ + if(arr[i] < arr[mn_ind]){ + mn_ind=i; //updating the min index + mn_ind_arr.clear(); + mn_ind_arr.add(i); + } + else if( arr[mn_ind]== arr[i]){ + mn_ind_arr.add(i); + } + } + return mn_ind_arr; + } + + public static void main(String[] args) { + int [] k = {8,7,8,5,6,5}; //sample test case with edge case for max_ind and min_ind functions + System.out.println(max_ind(k)); + System.out.println(min_ind(k)); + + } +} \ No newline at end of file diff --git a/Array_Functions/Min_Max_Functions/min_max.py b/Array_Functions/Min_Max_Functions/min_max.py new file mode 100644 index 0000000..5d0258d --- /dev/null +++ b/Array_Functions/Min_Max_Functions/min_max.py @@ -0,0 +1,27 @@ +def max_ind(arr): + mx_ind=0 #initializing the index with the max value as 0 + l=[] + for i in range(len(arr)): + if arr[i]>arr[mx_ind]: + l=[] #handling edge cases in case of multiple max indexes + l.append(i) + mx_ind=i #updating the max index + elif arr[i]==arr[mx_ind]: + l.append(i) + return l + +def min_ind(arr): + mn_ind=0 #initialising the index with the minimum value as 0 + l=[] + for i in range(len(arr)): + if arr[i]