CA 06 - Find the Maximum and Minimum Element in the Array



Min and Max in Array
Input: arr[] = [1, 4, 3, 5, 8, 6]
Output: [1, 8]
Explanation: minimum and maximum elements of array are 1 and 8.
Input: arr[] = [12, 3, 15, 7, 9]

Output: [3, 15]
Explanation: minimum and maximum element of array are 3 and 15.
MY CODE:
The min and max are the functions which shows the maximum and minimum element
class Solution:
   
class Solution: def getMinMax(self, arr): a = arr[0] # min b = arr[0] # max for c in range(1, len(arr)): d = arr[c] if d < a: a = d if d > b: b = d return [a, b]

Comments

Popular posts from this blog

CA 22 - Reverse a Linked List