Google Interview Question for Software Engineer / Developers


Country: United States




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

More details.

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

Do you justified text that occupies entire line like in microsoft word?

- InterviewPractice January 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess the question means this:
Given the line length 10 and given a word "hello"
output : "h e l l o " --> evenly distributed text

- Mark January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class UniformlyDisplayedTextWithSpace {
	public static String insertSpace(String str, int length) {
		int len;
		if (null == str || str.length() == 0 || (len = str.length()) >= length)
			return str;

		StringBuilder sb = new StringBuilder();
		while (len + str.length() < length) {
			for (int i = 0; i < str.length() - 1; i++) {
				if (Character.isAlphabetic(str.charAt(i)))
					sb.append(str.charAt(i)).append(" ");
				else
					sb.append(str.charAt(i));
			}
			sb.append(str.charAt(str.length() - 1));
			str = sb.toString();
			sb.setLength(0);
		}

		return str;
	}

	@Test
	public void testInsertSpace() {
		String str = "driver";
		String newStr = insertSpace(str, 30);
		System.out.println(newStr);
	}
}

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

the above program does not work it will fail for "hello" to be expanded to 11 characters. It returns only 9. In the following to check for the right amount of spaces I added '-' instead of whitespace.

public String addSpace(String s, int length){
        checkNotNull(s, "Input String cannot be null");
        checkArgument(s.length() < length, "Cannot expand input string of "+s.length() + " to require size of " + length);
        StringBuilder str = new StringBuilder("");
        int addition = length - s.length();
        int betweenSpaces = addition / s.length();
        int endSpace = (addition  % s.length()) + betweenSpaces;
        for(int i = 0 ; i < Math.ceil(endSpace / 2.0); i++)
            str.append("-");
        int i = 0;
        while(i < s.length()){
            str.append(s.charAt(i));
            if(i < s.length() -1) {
                for (int x = 0; x < betweenSpaces; x++)
                    str.append("-");
            }
            i++;
        }
        for(int x = 0 ; x < endSpace - Math.ceil(endSpace / 2.0); x++)
            str.append("-");
        return str.toString();
    }

- nogood March 20, 2015 | 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