VMWare Inc Interview Question for Interns


Country: United States
Interview Type: Phone Interview




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

Can you please explain what is expected when two strings are given, I mean what kind of comparison is expected?

- Victor March 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If the two strings are equal, then the method must return true, else it must return false.

- varunumesh77 March 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

First ensure the length of two strings are same,
Then, compare each character by its ascii value one by one. This will take care of case automatically.

Are there any other conditions ?

- arsragavan March 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes, you would also need to check if the references of the strings are same!

For example String str1 = new "Hello";
String str2 = str1;

In this case too, the strings are equal.

I was not able to figure out how to do the locale part, any idea how to tackle that?

- varunumesh77 March 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

str1.hashCode() == str2.hashCode()

- arsragavan March 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

C version:
Returns 0 if strings are same else non-zero value.

int my_strcmp ( char *s, char *t ) {
	while ( *s == *t ) {
		if ( *s == '\0' )
			return 0 ;
			
		s++ ;
		t++ ;
	}
	return ( *s - *t ) ;
}

- R@M3$H.N March 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what are the cases we should consider during string comparison?

- Kisley March 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if(str1==null&&str2==null) return true;
if(str1==null||str2==null) return false;
if(str1.length()!=str2.length()) return false;
int index1=0;
int index2=0;
while(index1<str1.length() && index2<str2.length()) {
if(str1.charAt(index1)!=str2.charAt(index2)) return false;
index1++;
index2++;
}
return true;

- freemail165 April 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		String str1 = "Hello";
		String str2 = "Hello";
		int found = 1;
		if (str1.length() == str2.length()) {
			for (int i = 0; i < str1.length(); i++) {
				if (str1.charAt(i) == str2.charAt(i)) {
					continue;
				} else {
					found = 0;
				}
			}
			if (found == 0) {
				System.out.println("Not Equal Strings");
			}else{
				System.out.println("Hurray the strings are equal");
			}

		} else {
			System.out.println("Not Equal Strings");
		}
	}

- VijayKalkundri September 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why do we need else { found = 0 }? as soon as we see that a char is not matching, we can return false.

- Naveen October 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This should the faster then the previous solution :

public static void main(String[] args) {
		String str1 = "Hello";
		String str2 = "Heleo";
		System.out.println((str1 != null) && (str2 != null)
				&& (str1.hashCode() == str2.hashCode()) && str1.equals(str2));
	}

- VijayKalkundri September 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This should the faster then the previous solution :

public static void main(String[] args) {
		String str1 = "Hello";
		String str2 = "Heleo";
		System.out.println((str1 != null) && (str2 != null)
				&& (str1.hashCode() == str2.hashCode()) && str1.equals(str2));
	}

- VijayKalkundri September 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

1.read each char from first string put it in map(key will be index and value will be that char)
2.read each char from second string and read char from map as well for that index
3. if both char are not same return false;
4 and at the end if map size and second string size are not same return false;
5 return true

- Anonymous April 01, 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