diff --git a/complexity Analysis/Dante's solutions/largest_secondsmallest/largest.js b/complexity Analysis/Dante's solutions/largest_secondsmallest/largest.js new file mode 100644 index 0000000..58ea820 --- /dev/null +++ b/complexity Analysis/Dante's solutions/largest_secondsmallest/largest.js @@ -0,0 +1,26 @@ +/** + * First Problem Statement: Given an array, we have to find the largest element in the array. + + + +Examples + +Plain Text +Example 1:Input: arr[] = {2,5,1,3,0};Output: 5Explanation: 5 is the largest element in the array. +Example2:Input: arr[] = {8,10,5,7,9};Output: 10Explanation: 10 is the largest element in the array. + */ + + +function findLargest(arr){ + + if(arr.length===0){ + return -1 + }else{ + return Math.max(...arr); + } +} + +//test +let array=[2,5,1,3,0] +let num=findLargest(array) +console.log(num) \ No newline at end of file diff --git a/complexity Analysis/Dante's solutions/largest_secondsmallest/secondsmallest.js b/complexity Analysis/Dante's solutions/largest_secondsmallest/secondsmallest.js new file mode 100644 index 0000000..ee3f0d0 --- /dev/null +++ b/complexity Analysis/Dante's solutions/largest_secondsmallest/secondsmallest.js @@ -0,0 +1,40 @@ + +/** + * + * Statement: Given an array, find the second smallest in the array. Print ‘-1’ in the event that it doesn’t exist. + + + +Examples + + + +Plain Text +Example 1:Input: [1,2,4,7,7,5]Output: Second Smallest : 2 + +  Second smallest : 2Explanation: The elements are as follows 1,2,3,5,7,7 and hence second smallest is 2 + +Example 2:Input: [1]Output: Second Smallest : -1 +  Second Largest : -1Explanation: Since there is only one element in the array, it is the smallest element present in the array. There is no second smallest element present.in the arra + */ + + + +function secondSmallest(arr){ + let minimum=Math.min(...arr) + let minIndex=arr.indexOf(minimum) + if(arr.length==0||arr.length==1){ + return -1 + } + else{ + arr.splice(minIndex,1) + return Math.min(...arr) + + + + } +} + +let array=[1,2,4,7,7,5] +let newArray=secondSmallest(array) +console.log(newArray); \ No newline at end of file