Skip to content

Commit f07c0c7

Browse files
authored
Fibonacci String
1 parent 77f9235 commit f07c0c7

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

CLFIBD/Main.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.*;
2+
3+
public class Main
4+
{
5+
static boolean check_fibo(ArrayList<Integer> n)
6+
{
7+
for (int i = 2; i < n.size(); i++)
8+
{
9+
if (n.get(i) != n.get(i - 1) + n.get(i - 2))
10+
{
11+
return false;
12+
}
13+
}
14+
return true;
15+
}
16+
17+
static String solve(String str)
18+
{
19+
HashMap<Character, Integer> a = new HashMap<>();
20+
for (int i = 0; i < str.length(); i++)
21+
{
22+
a.put(str.charAt(i), a.getOrDefault(str.charAt(i), 0) + 1);
23+
}
24+
if (a.size() < 3)
25+
{
26+
return "Dynamic";
27+
}
28+
ArrayList<Integer> n1 = new ArrayList<>(a.values());
29+
Collections.sort(n1);
30+
ArrayList<Integer> n2 = new ArrayList<>(n1);
31+
n2.set(0, n1.get(1));
32+
n2.set(1, n1.get(0));
33+
return check_fibo(n1) || check_fibo(n2) ? "Dynamic" : "Not";
34+
}
35+
36+
public static void main(String args[])
37+
{
38+
Scanner s = new Scanner(System.in);
39+
int x = s.nextInt();
40+
while (x-- > 0)
41+
{
42+
String str = s.next();
43+
System.out.println(solve(str));
44+
}
45+
s.close();
46+
}
47+
}

0 commit comments

Comments
 (0)