McAfee Interview Question for Applications Developers


Country: United States
Interview Type: Written Test




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

1) First reverse the entire string ( it gives like "dlrow olleh")
2) and then call/reverse word from first character to till space encounters.
3) It gives desired output.

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

#include<stdio.h>

void reverse(char *des,char *str)
{
char temp;
while(des<str)
{
temp=*des;
*des++=*str;
*str--=temp;
}
}
int main()
{
char str[]="Hello World";
printf("Original String is :: %s \n ",str);
char *temp=str;
char *dest=str;
while(*temp)
{
temp++;
if(*temp=='\0')
{
reverse(dest,temp-1);
}
//Finally Reversed String is junaT si eman yM
else if(*temp==' ')
{
reverse(dest,temp-1);

dest=temp+1;
}
//Finally Reversed String is yM eman si junaT
}
reverse(str,temp-1);
//Finally Reversed String is Tanuj is name My
printf("Finally Reversed String is :: %s",str);
//printf("Helo......");
getchar();
return 0;
}

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

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {

    string s("Hello World sdf4 45234");
    reverse(s.begin(), s.end());

    int start = 0;

    while(true) {
        int index = s.find(" ", start);
        if (index == s.npos) {
            reverse(s.begin() + start, s.end());
            break;
        }
        reverse(s.begin() + start, s.begin() + index);
        start = index + 1;
    }
    cout << s << endl;

    return 0;
}

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

public static void reverse(String input)
{
		
		String[] words = input.split(" ");
		int length = words.length;
		StringBuilder finalString = new StringBuilder(input.length());
		for(int i=length-1;i >= 0;i--)
		{
			finalString.append(words[i]);
			finalString.append(" ");
		}
		
		System.out.println("Result String: "+ finalString.toString());
		
	}

Input : Hello World
Output : World Hello

- priti2.jain August 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is the complexity of input.split...would it be O(n),where n is the length of the text given.....?

- dt August 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, you are right.

Internally, it(split method) uses a 2 pass routine. In the first pass, the index of the separator characters are discovered and stored. In the second pass, the string is "split" by calling Substring repeatedly and storing the results in an output array using the indices previously saved.

As such, the algorithm is effectively O(N), since it's doing linear passes through the input string.

- priti2.jain August 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string>
using namespace std;
void reverse(string &s)
{
	int l=s.length();
	char ch;
	for(int i=0;i<l/2;i++)
	{
		ch=s[i];
		s[i]=s[l-i-1];
		s[l-1-i]=ch;
	}
}

void str_reverse(string &s)
{
	int i=0,m,l=s.length(),j;
	char ch;
	reverse(s);
	while(i<=l)
	{
		j=i;
		while(s[i]!=' '&&s[i]!='\0')
		{
			i++;
		}
		m=(i-j)/2;
		for(int k=0;k<m;k++)
		{
			ch=s[j+k];
			s[j+k]=s[i-1-k];
			s[i-1-k]=ch;
		}
		i++;
	}
}

int main()
{
	string s;
	getline(cin,s);
    str_reverse(s);  
//reverse(s);
	cout<<s;
	return 0;
}

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

public class StringReverseExample {

    public static void main(String args[]) throws FileNotFoundException, IOException {

        //original string
        String str = "Sony is going to introduce Internet TV soon";
        System.out.println("Original String: " + str);

        //recursive method to reverse String in Java
        String reverseStr = reverseRecursively(str);
        System.out.println("Reverse String in Java using Recursion: " + reverseStr);

    }

    public static String reverseRecursively(String str) {

        //base case to handle one char string and empty string
        if (str.length() <= 1) {
            return str;
        }

        return reverseRecursively(str.substring(1)) + str.charAt(0);

    }
}

- trish August 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

subString() method of the String class always generates a new String object.

- june.pravin September 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class RevString {
    
    public static void main(String[] arg){
        
        String str="Muhammad Tariq Akram";
        String[] strArray = str.split(" ");
        int length=strArray.length;
        
        for(int i=length-1; i>-1; i--){
            System.out.print(strArray[i] + " " );
        }
    }
    
}

- Muhammad Tariq Akram August 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char c[20]="Hello World";

int l;
l=strlen(c);
char arr[l];
arr[0]=' ';
int i=1;
while(c[i-1]!=32)
{
arr[i]=c[i-1];
i++;

}
arr[i]='\0';
char arr1[l-i+1];
arr1[l]='\0';
while(c[l]!=32)
{
arr1[l-1]=c[l-1];
l--;
}
char *str=strcat(arr1,arr);
cout<<str;
}

- amitfet.sagar September 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void ReverseWords(String input)
    {
       String words[] = input.split(" ");
       
       int k = words.length-1;
       
       StringBuilder FinalString = new StringBuilder(k);
       
       for(int j=k; j>=0; j--)
       {
           FinalString.append(words[j]).append(" ");
       }
        System.out.println(FinalString);
    }

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

#include"stdafx.h"
#include"iostream"
#include"string"

using namespace std;
#define P system("pause")

int main()
{
string s = "Hello World";

string s1, s2;
s1.assign(&s[0], &s[5]);
s2.assign(&s[6], &s[11]);

string rets = strcat( strrev(const_cast<char*>(s1.c_str())), " ");
strcat(const_cast<char*>(rets.c_str()), strrev(const_cast<char*>(s2.c_str())));
strrev(const_cast<char*>(rets.c_str()));
cout<<rets.c_str()<<endl;
P;
return 0;
}

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

///
using System;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
reverseString("Hello how are you?");

Console.ReadLine();
}

private static void reverseString(string p)
{
int space = 0;
bool multiWord = false;
while (space != -1)
{
space = p.LastIndexOf(' ');
if (space != -1)
{
string wor = p.Substring(p.LastIndexOf(' '));
Console.Write(wor);
p = p.Substring(0, p.LastIndexOf(' '));
multiWord = true;
}
else
{
if (!multiWord)
{
Console.Write(p);
}
else
{
Console.Write(" " + p);

}
}
}
}
}
}
\\\

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

a = "My world is you"
print ' '.join(a.split()[::-1])
print a[::-1]

result:
you is world My
uoy si dlrow yM

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

public void reversesen(){
String[] word = s.split(" ");
for(int i=word.length-1;i>=0;i--){
result=result+word[i]+" ";
}
}

- Sathishwaran Selvaraj October 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def rev(str):
	s = str.split(" ")
	for i in range(len(s)-1,-1,-1):
		print(s[i],end=" ")


rev("Hello World")

- shukad333 October 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.DataInputStream;
import java.io.IOException;
public class stringreversal 
{
    public static void main(String args[])throws IOException
    {
        
        System.out.println("Enter the string to be reversed??");
        DataInputStream in = new DataInputStream(System.in);
        String abc= in.readLine();
        String arr[]=abc.split(" ");
        String ab;
        for(int i=0,j=arr.length-1;i<=j;i++,j--)
        {
            ab = arr[i];
            arr[i]=arr[j];
            arr[j]=ab;
        }
        for(int i=0;i<arr.length;i++)
        System.out.print(arr[i]+" ");
    }
}

- Yagyesh Tripathi November 12, 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