top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C: Find the string which is made up of maximum number of other strings ?

+4 votes
1,127 views

"Given an array of strings, find the string which is made up of maximum number of other strings contained in the same array. e.g. “rat”, ”cat”, “abc”, “xyz”, “abcxyz”, “ratcatabc”, “xyzcatratabc” Answer: “xyzcatratabc”

posted Oct 18, 2013 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

I would prefer LCS with dynamic programming.

for more ideas check following link
http://www.careercup.com/question?id=5647413305933824

answer Oct 18, 2013 by Pankaj Agarwal
+1 vote

Following will not just print the best rather print all in the order -

public static void main(String[] args) {
        ArrayList<String>list = new ArrayList<>();
        list.add( "rat");
        list.add( "cat");
        list.add( "abcxyz");        
        list.add( "abc");
        list.add( "xyz");
        list.add( "ratcatabc");
        list.add( "xyzcatratabc" );

        Map<String, Integer> map = new HashMap<String, Integer>();

        for(int i=0; i<list.size()-1; i++){
            String s = list.get(i);         
            for(int j=0; j < list.size(); j++){
                if(i==j){
                    continue;
                }
                if(list.get(j).contains(s)){
                    Integer v = map.get(list.get(j));
                    if(v == null){
                        map.put(list.get(j), 0);
                    }else{
                        map.put(list.get(j), v+1);
                    }
                }

            }   

        }
        System.out.println(map);        
    }
answer Oct 18, 2013 by Luv Kumar
Similar Questions
+6 votes

For example: It returns ‘b’ when the input is “abaccdeff”.

+5 votes

Help me to write a C program which can generate list of numbers which are palindrome in decimal and octal notion. You can take some max as a limit find out all numbers which satisfy the given property between 1 to n.

+8 votes

Convert the given string into palindrome with minimum number of appends(at end of the given string). O(n) algorithm will be appreciated ??

Input :=> Malayal
Output :=> Malayalam

+3 votes

A list contains a set of numbers, one number presents once and other numbers present even no. of times. Find out the number that occurs once in the list.

...