Amazon Interview Question for Interns


Country: United States
Interview Type: Phone Interview




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

public class Program
    {
        public static void Main(string[] args)
        {
            var dict = new Dictionary<string, int>();
            dict.Add("a", 1);
            dict.Add("aa", 1);
            dict.Add("aaa", 1);
            
            var input = "aaabaa";
            
            get_combinations(input, dict);
            
        }
        
        public static void get_combinations(string input, Dictionary<string, int> dict)
        {
            for (int i = 0; i < input.Length; i++)
            {
                for (int j = i ; j < input.Length ; j++)
                {
                    if (dict.ContainsKey(input.Substring(i, j-i+1)))
                    {
                        Console.WriteLine(input.Substring(i, j-i+1));
                    }
                }
            }
        }
    }

- abdelrahman.elbarbary December 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Find all substrings, find them in dictionary, if found, add to return list.

public void findSubStringInDictionary() {
		String s = "abcdefabcd";
		Set<String> d = new HashSet<String> (Arrays.asList("a", "cdf", "bcd", "ef"));
		System.out.println(findSubString(s,d));
	}

	public List<String> findSubString(String s, Set<String> dictionary) {
		List<String> retSet = new LinkedList<String>();
		for (int ii = 0; ii < s.length(); ii++) {
			for (int jj = ii; jj <= s.length(); jj++) {
				if (dictionary.contains(s.substring(ii,  jj))) {
					retSet.add(s.substring(ii,  jj));
				}
			}
		}
		return retSet;
	}

- Nick N. January 31, 2018 | 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