Java Algorithm
Date: Jul 2014
Level: Intermediate


INTERVIEW QUESTIONS

Company: Amdocs
Question Title: Java Algorithm
Language: Java
QUESTION DETAILS:

Given an array of strings as input, return an array of all those strings that have repeated chars that appear together. For e.g. in "hello" l and in "summer" m are repeated characters that appear together. However in "robot" o is not a repeated char as it does not appear consecutively.

repeatChars({"hello","robot","summer","elephant"}) = {"hello","summer"}


Here's the code:
This will print: [app, Hello, Summer]
import java.util.*;

class Fonts{
public static void main(String[] args)
{
printWordsWithAdjacentDupChars();
}
static void printWordsWithAdjacentDupChars(){
		String[] wl = {"app","By","Hello","Cat","Summer","way"};
		ArrayList<String>  al = new ArrayList<String> ();
		for (String word: wl){
		for (int i=0; i < word.length()-1;i++){
		if (word.charAt(i)== word.charAt(i+1)){
		al.add(word);
		break;
		}
		}
		}
		System.out.print(al);
		}
		}
All Questions