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 d88619c commit 2b294c9Copy full SHA for 2b294c9
3115-maximum-prime-difference.js
@@ -0,0 +1,32 @@
1
+const isPrime = num => {
2
+ for(let i = 2, s = Math.sqrt(num); i <= s; i++) {
3
+ if(num % i === 0) return false;
4
+ }
5
+ return num > 1;
6
+}
7
+/**
8
+ * @param {number[]} nums
9
+ * @return {number}
10
+ */
11
+var maximumPrimeDifference = function(nums) {
12
+ let fi = -1, li = nums.length
13
+ const n = nums.length
14
+ for(let i = 0; i < n; i++) {
15
+ const e = nums[i]
16
+ if(isPrime(e)) {
17
+ fi = i
18
+ break
19
20
21
+ for(let i = n - 1; i >= 0; i--) {
22
23
24
+ li = i
25
26
27
28
+
29
+ if(fi === -1) return 0
30
31
+ return li - fi
32
+};
0 commit comments