VMWare Inc Interview Question for Software Engineer / Developers






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

for swapping variable
num1 = num1 ^ num2 ;

num2 = num1 ^ num2 ;
num1 = num1 ^ num2 ;

- brijesh kumar jaiswal April 11, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for swapping variable

num1 = num1 - num2 ;
num2 = num2 + num1 ;
num1 = num2 - num1;

- brijesh kumar jaiswal April 11, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

reversing string
here n is length of string
for(i = 0 ; i < n/2 ; i++)
{
str[i] = str[i] - str[n-1-i];
str[n-1-i] = str[n-1-i] + str[i] ;
str[i] = str[n-1-i] - str[i];

}

- brijesh kumar jaiswal April 11, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

for(i = 0 ; i < n/2 ; i++)

Isn't "i" here considered a temp variable?

- Vick August 28, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

no, i is a counting variable I guess!
I suppose the idea is to convey how to use arithmetic operations for swapping.

- nik October 12, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Have two pointers a,one to the first character of the string and b one to the last. Swap both and increment a and decrement b. Recursively do this till till both are equal.

- prad March 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How will you swap 2 things without the temp variable.... This is the whole point of this question

- abhimanipal March 05, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a=2 b=3;

a=a+b;
b=a-b;
a=a-b;

- mbm June 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reverse(char *str, int len)
{
while(--len<=0)
{
*str ^=str[len];
str[len]^=*str;
*str=str[len];
str++;
}
}

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

void reverse(char *str, int len)
{
while(--len<=0)
{
*str ^=str[len];
str[len]^=*str;
*str=str[len];
str++;
}
}

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

You can NOT swap two numbers without using temporary variable,
above method may work for small number, consider two big numbers 65535 and 65534
your sum a=a+b overflows
i think even XOR wont work if u take negetive numbers

- anonymus February 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The method is correct:

x = 65535 and y= 65534

x = x - y = 65535-65534 = 1
y = y + x = 65534 + 1 = 65535
x = y - x = 65535 - 1 = 65534

we have x = 65534 and y = 65535.

- Sagar May 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

String reverseMe = "reverse me!";
for (int i = 0; i < reverseMe.length(); i++) {
    reverseMe = reverseMe.substring(1, reverseMe.length() - i)
        + reverseMe.substring(0, 1)
        + reverseMe.substring(reverseMe.length() - i, reverseMe.length());
 }
 System.out.println(reverseMe);

source - stackoverflow stivlo

- Anonymous August 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void(char *p)
{
int i,n;
n=strlen(p);
for(i=0;i<n/2;i++)
{
p[i]=p[i]^p[n-1-i];
p[n-1-i]=p[i]^p[n-1-i];
p[i]=p[i]^p[n-1-i];
}
}
int main()
{
char str[]="string";
void(reverse(str);
puts(str);
}

- Anonymous December 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what will be space complexity of this function:

String reverseMe = "reverse me!";
for (int i = 0; i < reverseMe.length(); i++) {
reverseMe = reverseMe.substring(1, reverseMe.length() - i)
+ reverseMe.substring(0, 1)
+ reverseMe.substring(reverseMe.length() - i, reverseMe.length());
}
System.out.println(reverseMe);


will it be O(n^2)? orO(n^3)

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

class Rev{
public static void main(String[] args)
{
String s="abcd";
int len=s.length();
for(int i=0;i<len*2;i++)
{
s=s.charAt(i)+s;
i++;
}
s=s.substring(0,len);
System.out.println(s);
}
}

- Abhimanyu Chopra August 14, 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