Google Interview Question for Software Engineer / Developers


Country: Switzerland
Interview Type: Phone Interview




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

I would propose the following solution:

public static String makeNumeronym(String s) {
	if (s == null || s.length() < 3) 	return s;
	int N = s.length();
	return s.charAt(0) + (N-2) + s.charAt(N-1) + "";
}

Btw, isn it that marcus -> m4s? Is it something the interviewer expected?

- autoboli April 23, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Does char + integer give a string in java??

- zsalloum April 23, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

YES! marcus -> m4s sorry for the typo

- Anonymous April 24, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@zsalloum, No but notice +"" which yields the String.

- autoboli April 27, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

module.exports = function (s) {
	var r = /^(.)(.{3,})(.)$/.exec(s);
	if (r) {
		r = r[1] + r[2].length + r[3];
	}
	return r || s;
};

- srterpe May 01, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

That's certainly a warm up. Python lets you answer this essentially in one line:

def makeNumeronym(word):
    return (word[0] + str(len(word[1:-1])) + word[-1]) if (isinstance(word, str) and len(word) >= 3) else word

This would be even shorter if it didn't do type checking and length checking.

- Javeed April 23, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

```ruby
{{string.size > 2 ? string[0] + (string.size - 2).to_s + string[-1] : string}}
```

- Alex April 23, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{s.size > 2 ? s[0] + (s.size - 2).to_s + s[-1] : s}}

- Alex April 24, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String getNumeronym(String str){
    if(str == null){
        return null;
    }
    if(str.length() < 3){
        return str;
    }
    int length = str.length();
    return str.charAt(0) + Integer.toString(length - 2) + str.charAt(length -1);
}

- zortlord May 21, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Main {

public static void main(String[] args) {

String s = "house";
String expected = makeNumeronym(s);

System.out.println(expected);

}

private static String makeNumeronym(String s) {

int x = s.length() -1;
String y = s.substring(1, x);
int z = y.length();
String Numeronym = s.charAt(0) + String.valueOf(z) + s.charAt(x);

return Numeronym;

}
}

- Anonymous May 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

///
public class Main {

public static void main(String[] args) {

String s = "house";
String expected = makeNumeronym(s);

System.out.println(expected);

}

private static String makeNumeronym(String s) {

int x = s.length() -1;
String y = s.substring(1, x);
int z = y.length();
String Numeronym = s.charAt(0) + String.valueOf(z) + s.charAt(x);

return Numeronym;

}
}///

- Anonymous May 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Main {

	public static void main(String[] args) {
	
		String s = "house";
		String expected = makeNumeronym(s);
		
		System.out.println(expected);

}

	private static String makeNumeronym(String s) {
		
		int x = s.length() -1;
		String y = s.substring(1, x);
		int z = y.length();
		String Numeronym = s.charAt(0) + String.valueOf(z) + s.charAt(x);
		
		return Numeronym;
		
	}

}}

- Anonymous May 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Main {

	public static void main(String[] args) {
	
		String s = "house";
		String expected = makeNumeronym(s);
		
		System.out.println(expected);

}

	private static String makeNumeronym(String s) {
		
		int x = s.length() -1;
		String y = s.substring(1, x);
		int z = y.length();
		String Numeronym = s.charAt(0) + String.valueOf(z) + s.charAt(x);
		
		return Numeronym;
		
	}
}

- Kyle May 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Main {

	public static void main(String[] args) {
	
		String s = "house";
		String expected = makeNumeronym(s);
		
		System.out.println(expected);

}

	private static String makeNumeronym(String s) {
		
		int x = s.length() -1;
		String y = s.substring(1, x);
		int z = y.length();
		String Numeronym = s.charAt(0) + String.valueOf(z) + s.charAt(x);
		
		return Numeronym;
		
	}
}

- Kyle May 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Africanization

- Kyle May 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is the question saying? I did not get it

- jigili August 23, 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