FactSet Research Systems, Inc Interview Question for Software Engineer / Developers






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

int main()
{
   int a[]= { 5, 5, 5, 2, 2 };
int num1=a[0],count1=1;
int num2,count2=0;
int i;
for(i=1;i<5;i++)
{
  if(a[i]==num1)
  count1++;
  else
   {
    if(count2==0)
    {
      count2=1;
      num2=a[i];
    }
    else if(a[i]==num2)
     count2++;
   }
}

if(count1==3&&count2==2)
printf("true");
else if(count2==3&&count1==2)
printf("true");
else
printf("false");
   return 0;
}

- kamal August 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if there is another number e.g { 5, 5, 5, 2, 2 ,4} ? As I think code will not work then

- Ankit September 23, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

1. Use extra array to count each number times. For porker, int array[15]={0}
2. Go through each number i , array[i]++;
3. Go through array[], it contains only 2 or 3.

- wavelet August 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

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

#include <stdio.h>
#include <conio.h>
bool func1(int a[]);
void main()
{
int a[5],i;
printf("Enter");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
printf("\nReturns %d",func1(a));
getch();
}
bool func1(int s[5])
{
int i,j,temp=0,count=0,y=1,z=0;
printf("\nSorted Elements");
for(i=0;i<5;i++)
{
for(j=i;j<5;j++)
{
if(s[i]>s[j])
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
printf("\n%d",s[i]);

}
printf("\nDistinct Elements ");
for(i=0;i<5;i++)
{
if(s[i]!=s[i+1])
{
printf("\n %d",s[i]);
count++;

}

}
printf("\nCount=%d",count);
for(i=0;i<5;i++)
{
if(s[i]==s[i+1])
{
y++;
z=y;
}
else
{
printf("\n%d repeated %d times",s[i],y);
y=1;
}
}
if(count==2 && z>1 && z<4){
printf("\nz=%d",z);
return true;}
else
return false;
}

- R.Karthik August 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

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

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

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

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

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

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

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

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

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

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

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

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

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

WHO THE HELL THIS CRAZY ANONYMOUS IS? LET BANG HIM :-)

- CRAZY FUCKER! August 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

def pocker_func(arr);
number_count=defaultdict(int)
for val in arr:
number_count[val]+=1
inters = set(number_count.values()).intersection(set([2,3])
if inters == set([2,3]): return True
else: return False

- Anonymous August 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey5827" class="run-this">#include <stdio.h>
#include <conio.h>
bool func1(int a[]);
void main()
{
int a[5],i;
printf("Enter");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
printf("\nReturns %d",func1(a));
getch();
}
bool func1(int s[5])
{
int i,j,temp=0,count=0,y=1,z=0;
printf("\nSorted Elements");
for(i=0;i<5;i++)
{
for(j=i;j<5;j++)
{
if(s[i]>s[j])
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
printf("\n%d",s[i]);

}
printf("\nDistinct Elements ");
for(i=0;i<5;i++)
{
if(s[i]!=s[i+1])
{
printf("\n %d",s[i]);
count++;

}

}
printf("\nCount=%d",count);
for(i=0;i<5;i++)
{
if(s[i]==s[i+1])
{
y++;
z=y;
}
else
{
printf("\n%d repeated %d times",s[i],y);
y=1;
}
}
if(count==2 && z>1 && z<4){
printf("\nz=%d",z);
return true;}
else
return false;
}

</pre><pre title="CodeMonkey5827" input="yes">
</pre>

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

1) The return can be true only if there are only 2 distinct integers coming in the input array.
2) Use a 2x2 array to store the number and frequency of the number.
3) After the scan through the input, see if the frequency matches the required condition for a true return.

public bool PokerFun(int[] inputArray)
        {
            int[][] containerArray = new int[2][];
            for (int i = 0; i < 2; i++)
            {
                containerArray[i] = new int[2];
                for (int j = 0; j < 2; j++)
                {
                    containerArray[i][j] = 0;
                }
            }

            for (int i = 0; i < inputArray.Length; i++)
            {
                if (containerArray[0][0] != 0 && containerArray[0][0] == inputArray[i])
                {
                    containerArray[0][1]++;
                }
                else if (containerArray[0][0] == 0)
                {
                    containerArray[0][0] = inputArray[i];
                    containerArray[0][1]++;
                }
                else if (containerArray[1][0] != 0 && containerArray[1][0] == inputArray[i])
                {
                    containerArray[1][1]++;
                }
                else if (containerArray[1][0] == 0)
                {
                    containerArray[1][0] = inputArray[i];
                    containerArray[1][1]++;
                }
                else
                {
                    return false;
                }
            }

            if ((containerArray[0][1] == 2 || containerArray[0][1] == 3)
                && (containerArray[1][1] == 2 || containerArray[1][1] == 3))
            {
                return true;
            }

            return false;
        }

Test input arrays:

int[] inputArray1 = new int [] { 1, 1, 2, 2, 2 };

int[] inputArray2 = new int[] { 1, 2, 2, 2, 2 };

int[] inputArray3 = new int[] { 1, 1, 3, 2, 2 };

int[] inputArray4 = new int[] { 1, 1, 2, 5, 4 };

int[] inputArray5 = new int[] { 1,3, 2, 4, 5 };
Worked well with the tests I have.

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

This iz perfect

- krishna August 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Kamal's answer seems perfect.

- anshulzunke September 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Kamal's Answer could have been better if he just places that else if block before else and letting else block at the last!!!

- Pavan December 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Counter {
	public  Counter(int a[]) {
		int first=a[0],flag=0,flag2=0,second=0;
		for (int i=1;i<5;i++) {
			if (first==a[i])
				flag++;
			else{
				if (flag2==0)
					second=a[i];
				if(second==a[i])
					flag2++;
				else
					break;
			}
		}
		if ((flag==1&&flag2==3)||(flag==2&&flag2==2))
			System.out.println("Three of a kind");
		else
			System.out.println("Incorrect format");
	}
}
public class TwoThree {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] a={1,2,1,2,2};
		Counter obj= new Counter(a);
	}

}

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

How about using Hashmap, to store the frequency of occurrences as a value?? I can see solution with O(n) space complexity, is there a better solution to this?

Thanks in advance

- Amit Nadkarni October 12, 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