def dynamic_string(string):
count_list = [string.count(x) for x in set(string)]
count_list.sort()
check = 1
if len(count_list) < 3:
return 'Dynamic'
if count_list[2] != count_list[1] + count_list[0]:
count_list[0], count_list[1] = count_list[1], count_list[0]
for i in range(len(count_list)-1, 1, -1):
if count_list[i] != count_list[i-1] + count_list[i-2]:
check = 0
break
if check == 1:
return 'Dynamic'
else:
return 'Not'
output = ""
user_input = int(input())
for i in range(user_input):
to_check = input()
output += dynamic_string(to_check) + ' \n'
print(output)
I do get the Wrong Answer notification, but im really lost and stuck on what cases my code can’t handle properly. Any help or hints would be appreciated.
T = int(sys.stdin.readline().strip())
ans = []
for i in range(T):
x = sys.stdin.readline().strip()
ans.append(solve(x))
for j in range(T):
print(ans[j]) #solve(SI)
Why is this wrong. I used an extra flag variable to maintain a single occurence of True to replace the need of swapping. Which test cases does my code fail?
for t in range (int(input())):
s = list(input().strip())
r = sorted(s)
x = set(r)
a = []
flag = 0
count = 0
for n in x:
a.append(r.count(n))
val = sorted(a)
for k in range(2, len(val)):
if val[k] == val[k-1]+val[k-2]:
fib = True
if fib:
flag = 1
else:
fib = False
if fib or flag or len(x)<3:
print("Dynamic")
else:
print("Not")
#include #include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
string s;
cin>>s;
int l = s.length();
char a[l];
strcpy(a, s.c_str());
int sum[123];
for(int i=0;i<123;i++)
sum[i]=0;
for(int i=0;i<l;i++)
{
int v = (int)a[i];
sum[v]=sum[v]+1;
I think this problem can be solved using logic of AP Series.But our series will star from second element of series which is sort.Correct me if i am wrong.
please suggest were i am wrong
enter code here
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char a[1000001];
int main()
{
register int i,j,k,cnt,max,sum,sum2,l,n;
int t,b[27];
float s;
scanf("%d",&t);
However, it incorrectly determines that the string “aaaabcccxxxxxxxxxxyyyyyyyyzwp” is NOT dynamic. However, the non-zero counts for this string are, in sorted order, 1 1 1 1 3 4 8 10. Clearly 1 + 3 == 4 here, so it appears this should be dynamic. Am I missing something, or is your test data simply not complete?
I couldn’t find any issues here in the code!
It’s working fine with all possible test cases I can think of !
Can you please help in finding out the problem?? It’s showing wrong answer (WA).
def clfibd(occ):
for i in range(len(occ)-1):
for j in occ[i+1:]:
if (occ[i] + j) in occ:
return "Dynamic"
return 'Not'
for _ in range(int(input())):
s = input()
alpha = set()
for i in range(len(s)):
alpha.add(s[i])
if len(alpha) < 3:
print('Dynamic')
else:
occ = list()
for i in alpha:
occ.append(s.count(i))
occ.sort()
print(clfibd(occ))
At line 7 checking index 2 does not make any difference. You need to check it for index 3 (considering index from 0). For example-- if your sorted list looks like 3 4 7 10 then you have to swap 3 and 4 to satisfy the condition of being dynamic for 10 ( as 7+4=11 and 7+3=10). But on the other hand if you swap 3 and 4 for 7 it does not really make any difference.