There was an error while loading. Please reload this page.
1 parent ed2d8e3 commit c8f5e01Copy full SHA for c8f5e01
adhoc/incre-decre-sqaure-sort.js
@@ -0,0 +1,22 @@
1
+const fun = (n, val) => {
2
+ if (val >= 10 && parseInt((val + "").split("").sort((x, y) => x < y).join("")) === n)
3
+ return 1;
4
+ if ((val - 1) === n) {
5
6
+ }
7
+ if (val > n) {
8
+ return 9999;
9
10
+ if (val === n) {
11
+ return 0;
12
13
+ let a = 1 + fun(n, val + 1);
14
+ let b = 1 + fun(n, Math.pow(val, 2));
15
+ return Math.min(a, b);
16
+}
17
+
18
+console.log(fun(3, 2) + 2);
19
+console.log(fun(5, 2) + 2);
20
+console.log(fun(15, 2) + 2);
21
+console.log(fun(61, 2) + 2);
22
+console.log(fun(18, 2) + 2);
0 commit comments