surendrapandey3788
BAN USER- 0of 0 votes
AnswersSituation - You have millions of records(Strings) and user is typing "abc" in search box . Your task is to display strings from records in the sequence.
- surendrapandey3788 in India
e.g String in the record contain "abc" starting should appear first, then string which has "abc" in the second, should apprear later as below.
String - fabcsdf,asdfabc,dfadsfsdfabc,abckdf,ddfabc...
Displays suggestion like....
abckdf
fabcsdf
ddfabc
asdfabc
dfadsfsdfabc
Question - Which data structure you would use to stor this ?
And how will you implement to get this(shorted) result| Report Duplicate | Flag | PURGE
Nagarro Java Developer Java
public static void main(String[] args) {
System.out.println("Enter the number of rows");
Scanner s =new Scanner(System.in);
int num= s.nextInt();
for(int j = 1 ;j<num;j++){
if(j%2 !=0){
for(int k= 0; k<7; k++){
System.out.print(j);
}
System.out.print(j+1);
}else{
System.out.print(j+1);
for(int k=0; k<7;k++){
System.out.print(j);
}
}
System.out.println();
}
}
public class ParentClassStatic {
public static String encodeRepeatedChars(String source) {
StringBuilder sb = new StringBuilder();
Map<Character, Integer> map = new HashMap<Character,Integer>();
for(int i= 0; i<source.length(); i++){
map.put(source.charAt(i), map.containsKey(source.charAt(i))? map.get(source.charAt(i))+1 : 1 );
}
Set<Entry<Character, Integer>> set = map.entrySet();
for(Entry<Character,Integer> e : set){
sb.append(e.getValue()+""+e.getKey());
}
return sb.toString();
}
public static void main(String[] args) {
String example = "aaaggbbbbc";
System.out.println(encodeRepeatedChars(example));
}
}
}
- surendrapandey3788 February 03, 2017