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.
The below code is giving a bad result but getting accepted as Correct answer:
For input “ppppmmnnooooppqq” we should expect “Not”. But this code will print “Dynamic” which is not correct. Looks like there are no tests that have only last few frequencies following fibonacci sequence while the rest are not, in the sorted frequencies. Please check. Thanks!
def fibFound(x):
found = True
if (x[-1] != (x[-2] + x[-3])):
found = False
return found
def dyn(s):
res = False
u = [s.count(x) for x in set(s)]
if ((len(u) < 3) or (fibFound(sorted(u)))):
return True
else:
return False
try:
t = int(input())
for i in range(0, t):
s = input()
if (dyn(s)):
print("Dynamic")
else:
print("Not")
except EOFError as e:
pass