Amdocs Interview Question for Developer Program Engineers


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

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);
		
	}

- Juan July 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class FindConcecutiveCharacter {

	public static String[] findConcecutive(String[] arr) {

		String temp = null;
		
		int len=arr.length;
		
		String[] finalArray = new String[len];
		for(int i=0;i<len;i++){
			char[] temparr=arr[i].toCharArray();
			for(int j=0;j<temparr.length-1;j++){
				if(temparr[j]==temparr[j+1]){
					finalArray[i]=arr[i];
				}
					
			}
		}
		
		return finalArray;
	}
	
	public static void main(String[] args) {
		String [] array={"hello","robot","summer","elephant"};
		String [] array1=findConcecutive(array);
		for(int i=0;i<array1.length;i++){
			System.out.println(array1[i]);
		}
	}
}

- Shishir July 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

array length is same.remove null too

- ruhi July 25, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class AmdocsInterviewQuestionDeveloperProgramEngineers {

    public static void main(String[] args) {
        String[] wordArray = {"hello", "robot", "summer", "elephant"};
        System.out.println(Arrays.toString(repeatChars(wordArray)));
    }

    private static String[] repeatChars(String[] wordArray) {
        List<String> result = new LinkedList<String>();
        //
        for (String word : wordArray) {
            for (int i = 1; i < word.length(); i++) {
                if (word.charAt(i - 1) == word.charAt(i)) {
                    result.add(word);
                    break;
                }
            }
        }
        //
        return result.toArray(new String[result.size()]);
    }
}

- lexandro2000 July 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Usage:

python consecutivechars.py hello,robot,summer,elephant
hello
summer

Script:

#!/usr/bin/env python


import sys

def has_consecutive(word, prev_ch):
    if not word:
        return False
    elif word[0] == prev_ch:
        return True
    else:
        return has_consecutive(word[1:], word[0])

if __name__ == '__main__':
    if len(sys.argv) < 2:
        sys.exit(2)
    words = [word.strip() for word in sys.argv[1].split(',') if word.strip()]
    print '\n'.join([word for word in words if has_consecutive(word, '')])

Could be optimized in C easily for efficiency, to have an array of pointers of all word beginnings (NULL truncate each, in place), and recurse on &word[1] and word[0] in has_consecutive instead of using the list operations in Python.

- Dan July 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*
        Problem: Return an array of strings that have repeated characters together
     */
    public static String[] findConsecutiveCharacters(String[] arr)
    {
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < arr.length; i++)
        {
            String s = arr[i];
            for (int j = 0; j < s.length() - 1; j++) {
                if (s.charAt(j + 1) == s.charAt(j)) {
                     arrayList.add(arr[i]);
                }
            }
        }
        return arrayList.toArray(new String[arrayList.size()]);
    }

Similar solution to another poster here but I used ArrayList append so there aren't so many nulls in the final result array. This solution has a similar algorithm to what appears in Cracking the Coding Interview on Problem 1.5 Encode String.

- Johnb July 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public ArrayList<String> getRepeat(ArrayList<String> str){
int j;
ArrayList<String> atr = new ArrayList<String>();
for(String i : str){
for(j=1;j<i.length();j++){
if(i.charAt(j)==i.charAt(j-1))
{
atr.add(i);
}
}
}

return atr;
}

- Anonymous July 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def repeatChar(words):
    duplicate_string = []
    for string in words:
        strings = list(string)
        for i in range(0,len(string) - 1):
            if strings[i] == strings[i + 1]:
                duplicate_string.append(string)
    return duplicate_string

- Cyberomin August 10, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More