Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 1
TEST CASE TROUBLE T__T
import java.util.Scanner; public class DejaVu { public static void main(String[] args) { Scanner input = new Scanner(System.in); String S1 = input.next(); String ABC = "abcdefghijklmnopqrstuvwxyz"; char [] A = S1.toCharArray(); char [] c = ABC.toCharArray(); int [] d= new int[26]; int sum = 0; for (int p=0;p<26;p++){d[p]=0;} for(int i=0; i<S1.length(); i++) {for(int j=0; j<26; j++){ if(A[i]==c[j]){d[j]++; sum+= d[j];} if(d[j]>=2){break;} } } if(sum==A.length){System.out.println("Unique");} else {System.out.println("Deja Vu");} } } My code just through 4/5 test cases, so I can't gain 50 exp as expect. :((( Could someone help me figure out the shot coming, please...
5 Answers
+ 5
Run this code and check whether this works or not.
import java.util.Scanner;
public class DejaVu
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String S1 = input.next();
String ABC = "abcdefghijklmnopqrstuvwxyz";
char [] A = S1.toCharArray();
char [] c = ABC.toCharArray();
int [] d= new int[26];
int sum = 0;
for (int p=0;p<26;p++){d[p]=0;}
for(int i=0; i<S1.length(); i++)
{for(int j=0; j<26; j++){
if(A[i]==c[j]){d[j]++; sum+= d[j];}
if(d[j]>2){break;} } }
if(sum==A.length){System.out.print("Unique");}
else {System.out.print("Deja Vu");}
}
}
+ 3
RnT.Lee you are right
Actually I have made one change in code.
You can right greater than 2 instead of greater than or equal to 3.
+ 1
Swapnil OMG, it worked. @@ but I don't get it. What the difference between "counter>=2" and "counter>=3"?? "Repeated" means there are 2 or more of same letter in the input string, isn't it?
0
maybe you should also take into account capital letters.
0
Super