McAfee Interview Question for Applications Developers


Country: United States
Interview Type: Written Test




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

1. Create a hash of chars found as key and their position in array as value: Hash<char,pos>
2. Parse each char at a time ,
- check if it exists in the hash , if yes mark the pos = -1 in hash table
-if it doesnt exist, add the char and its position to the hash.
3. parse the hash to check if a char has pos != -1 and is minimum - thats our answer

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

This is what I would have done.
And if alphabest size is manageable (e.g. 256 Ascii), we can use an array:

<suitable signed integer type> position[256];

>=0 can mean position
-1 never seen
-2 seen more than once
or something similar

- bigphatkdawg September 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Well that's pretty simple. You just need a char variable and a bool variable.
Store the first letter from the respective string in the char variable, then initialize the bool variable with, let's say, 1 (you have to do this every time you store a letter in the char variable).
Compare the letter with the rest of the letters (just the ones in front of said letter, if you want to be efficient); if you found an identical letter, change the bool variable with 0.
Repeat these two steps until either the bool variable remained unchanged (and the letter stored at that time is your answer), or you reached the end of the string (meaning there is no non-duplicate letter in that string)

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

not correct. this will return f, for example input, because these cannot detect second f

- 0xFFFFFFFF August 16, 2013 | Flag
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("efficiency");
bool* array = new bool[s.size()];
fill(array, array + s.size(), false);
bool* pb = array;
for (int i = 0; i < s.size() - 1; i++) {
for (int p = i + 1; p < s.size(); p++) {
if (s[i] == s[p]) {
array[i] = array[p] = true;
}
}
}
while(*pb) pb++;
cout << s[pb - array] << endl;
delete [] array;
return 0;
}

- OxFFFFFFFF 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("efficiency");
    bool* array = new bool[s.size()];
    fill(array, array + s.size(), false);
    bool* pb = array;
    for (int i = 0; i < s.size() - 1; i++) {
        for (int p = i + 1; p < s.size(); p++) {
            if (s[i] == s[p]) {
                array[i] = array[p] = true;
            }
        }
    }
    while(*pb) pb++;
    cout << s[pb - array] << endl;
    delete [] array;
    return 0;
}

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

import java.util.Arrays;

/**
 * @author Muhammad Tariq Akram
 */
public class FirstNonDuplicateLetter {
    
    public static void main(String[] arg){
        
    String str="12345123456789";
    char[] myArray= str.toCharArray();
    boolean isMatchFound=true;
    
    
    for(int i=0; i<myArray.length; i++){
         
        if (isMatchFound==false){
            System.out.println("Result =" + myArray[i-1] );
            break;
        }
        
        isMatchFound=false;
        
        for(int j=i+1; j<myArray.length; j++){
            if (myArray[i] == ' '){
                isMatchFound = true;
                break;
            }else if (myArray[i] == myArray[j]){
                myArray[j]= ' ';
                isMatchFound = true;
                break;
            }
        }
        
    }
    
    }
    
}

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

for every next char which is matched, i have to put some thing , any thing to identify that i already has this char , so that i dont need to bother to match it again...!

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

import java.util.Stack;


public class C {

public static void main(String[] args) {

String str = "efficiency";

char[] arr = str.toCharArray();

Stack<Character> st = new Stack<Character>();
Stack<Character> st1 = new Stack<Character>();

for(int i=0;i<arr.length-1;i++){

for(int j=i+1;j<arr.length-1;j++){

if(arr[i] == arr[j]){

st.push(arr[i]);
}

}
}

for(int i=0;i<arr.length;i++){

if(!(st.contains(arr[i]))){

st1.push(arr[i]);

}
}

System.out.println(st1);
}
}

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

Please change last line to:
System.out.println(st1.elementAt(0));

- Learner August 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Stack;


public class C {

public static void main(String[] args) {

String str = "efficiency";

char[] arr = str.toCharArray();

Stack<Character> st = new Stack<Character>();
Stack<Character> st1 = new Stack<Character>();

for(int i=0;i<arr.length-1;i++){

for(int j=i+1;j<arr.length-1;j++){

if(arr[i] == arr[j]){

st.push(arr[i]);
}

}
}

for(int i=0;i<arr.length;i++){

if(!(st.contains(arr[i]))){

st1.push(arr[i]);

}
}

System.out.println(st1.elementAt(0));
}
}

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

fg/.,[ji

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

public class FirstNonDuplicate 
{
    public static void main (String [] args)
    {
        char c = FindFirstNonDuplicate("efficiency");
        if (c != '?')
            System.out.println("First non-duplicate character is "+ c);
        else 
            System.out.println("Error: There is no duplicate.");
    }
    
    public static char FindFirstNonDuplicate(String str)
    {
        str = str.trim();
        str = str.toLowerCase();
        int [] sum = new int[26];
        for (int i=0; i<sum.length; i++)
            sum[i] =0;
        
        for (int i=0; i<str.length(); i++)
        {
            sum[str.charAt(i)-'a']++;
        
        }
        
        for (int i=0; i<sum.length; i++)
        {
            if (sum[i] == 1)
            {
                return (char)(i+'a');
            }
        }
        
        return '?'; 
    }
}

- jabi.habash December 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package nonDuplicate;

import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

public class FirstNonDuplicate {

/**
* @param args
*/
public static void main(String[] args) {
String s = "efficiency";
FirstNonDuplicate fND = new FirstNonDuplicate();

char firstNonDuplicate = fND.findFirstNonDuplicate(s);
System.out.println(firstNonDuplicate);
}

private Character findFirstNonDuplicate(String s){
if(s.length()==0){
return null;
}

Stack<Character> stack = new Stack<Character>();
List<Character> list = new LinkedList<Character>();

char[] characters = s.toCharArray();

for(int i=0;i<characters.length;i++){
stack.push(characters[i]);
}

while(!stack.isEmpty()){
Character tempChar = stack.pop();
if(list.contains(tempChar)){
list.remove(tempChar);
}else{
list.add(tempChar);
}
}

int size = list.size();
Character firstNonDuplicate = list.get(size-1);

return firstNonDuplicate;
}

}

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

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string input = "efficiency";
List<char> convertion = input.ToCharArray().ToList();
foreach (char ch in input.ToCharArray())
{
int count = convertion.Count(c => c == ch);
if (count == 1)
{
Console.WriteLine("output - " + ch);
break;
}
}
Console.Read();
}
}
}

- Anonymous August 15, 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