We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 131a270 commit 7c8a66fCopy full SHA for 7c8a66f
src/_Problems_/find-2nd-max/index.js
@@ -0,0 +1,22 @@
1
+/**
2
+ * You may find it easy but it's tricky for few
3
+ * Input - [9, 2, 3, 6]
4
+ * Output - 6
5
+ */
6
+
7
+function findSecondMax(arr) {
8
+ let max = arr[0];
9
+ let max2 = 0;
10
11
+ for (let el of arr) {
12
+ if (el > max) {
13
+ max2 = max;
14
+ max = el;
15
+ }
16
17
+ if (el < max && el > max2) {
18
+ max2 = el;
19
20
21
+ return max2;
22
+}
0 commit comments