Skill Subsist Impulse Ltd Interview Question for Data Scientists


Country: India
Interview Type: Written Test




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

int[] a = { 1, 2, 1, 0, 5, 2, 4, 2, 3, 0, 1, 3, 2, 4 };
            Dictionary<int, int> maxrepeatnumbers = new Dictionary<int, int>();
            foreach (var item in a)
            {
                if(!maxrepeatnumbers.ContainsKey(item))
                {
                    maxrepeatnumbers.Add(item, 1);
                }
                else
                {
                    maxrepeatnumbers[item]++;
                }
            }

            Console.Write(string.Join(",", maxrepeatnumbers.OrderByDescending(s => s.Value).Select(v=> v.Key)));

- Dhenu April 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

a = [1, 2, 1, 0, 5, 2, 4, 2, 3, 0, 1, 3, 2, 4]
ms = mset(a)
l = list( ms.entries )
sortd( l ) :: { $.left.value < $.right.value } 
println( str( l , ',') -> { $.key } )

- NoOne April 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.util.Arrays;

/*
 * Find the highest frequency number in an array
 * That is in a number the highest repeating number
 */
public class HighestFrequencyNumber {
int[] a = {1, 2, 1, 0, 5, 3, 4, 2, 3, 0, 1, 3, 2, 4,3};
public void sortArray(){
	 Arrays.sort(a);
}
public void printArray(){
	for(int i: a){
		System.out.print(i+" ");
	}
	System.out.println();
}
public void findHigestFreqNumebr(){
	int size = a.length;
	int freq1=0;
	int freq2 = 0;
	int i=0;
	int num=0;
	printArray();
	while(i<size-1){
		if(a[i]==a[i+1]){
			freq1++;
		}
		else
		{
			if(freq1>freq2){
			freq2 = freq1;
			num = a[i];
			}
			freq1=0;
		}
		i++;
	}
	System.out.println("number "+num+" freq "+(freq2+1));
}
public static void main(String[] args){
HighestFrequencyNumber highfreq = new HighestFrequencyNumber();
highfreq.sortArray();

highfreq.findHigestFreqNumebr();
}
}

The total time complexity is O(nLogn) for Arrays.sort and for traversing through the array calculating the highest is O(n) so total being O(n)+O(nLogn)

- venkatareddi92 April 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

var input = [1, 2, 1, 0, 5, 2, 4, 2, 3, 0, 1, 3, 2, 4];
var count = {};

input.forEach(function(el){
    count[el] = count[el] + 1 || 1
});

console.log(Object.keys(count).sort(
  function(a, b){ return count[b] - count[a];}
))
console.log(count[5])

- Vladimir April 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

var input = [1, 2, 1, 0, 5, 2, 4, 2, 3, 0, 1, 3, 2, 4];
var count = {};

input.forEach(function(el){
    count[el] = count[el] + 1 || 1
});

console.log(Object.keys(count).sort(
  function(a, b){ return count[b] - count[a];}
))

- Vladimir April 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

/* It works*/
#include<stdio.h>
#include<conio.h>
main()
{
int num[100], count[100], arr[100];
int i, j, k, l = 0, n, a = 0, b, d;
int c = 0;
clrscr();
printf("enter number of elements");
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &arr[i]);
for (i = 0; i < 100; i++)
num[i] = NULL;
for (i = 0; i < n; i++)
{
b = arr[i];
a = 0;
for (k = 0; k < l; k++)//check whether the number is already scanned or not
{
d = 0;
c = num[k];
d = check(b, c);
if (d != 0)
{
a++;
}
}

if (a == 0)//if number is not already scanned
{
c = 0;
for (j = 0; j < n; j++)//check the array with same numbers
{
if (arr[i] == arr[j])
c++;
}

num[l] = arr[i];
count[l] = c;
++l;
}
}

for (i = 0; i < l; i++)
{
for (j = i + 1; j < l; j++)
{
if (count[i] < count[j])
{
a = count[i];
count[i] = count[j];
count[j] = a;
a = num[i];
num[i] = num[j];
num[j] = a;
}
}
}
printf("\n");
for (i = 0; i < l; i++)
printf("%d\t", num[i]);
getch();
}

check(int b, int c)
{
int k, a = 0;
if (b == c)
return 1;
else
return 0;
}

- Shouri April 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How come "5" is in the output? It is not repeated....
And why output is not sorted or First come first serve (like this "1 2 0 4 3")

- rasmiranjanbabu April 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

And to me here the max repeating number is "2", so output should be "2"

- rasmiranjanbabu April 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question is to print the number in descending order based on frequency(number of occurrence) .

1- Create an hashmap with key as number and value as the occurrence. O(1)
2- Traverse the array, Increase the count(value in hash) if the number is repeated. else put value = 1 if number came first time. O(n)
3- Sort the hashMap based on value and print it. O(nlogn)

Total time complexity O(n) + O(nlogn) => O(nlogn)

- azambhrgn April 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*It works*/

#include<stdio.h>
#include<conio.h>
main()
{
	int num[100], count[100], arr[100];
	int i, j, k, l = 0, n, a = 0, b, d;
	int c = 0;
	clrscr();
	printf("enter number of elements");
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	for (i = 0; i < 100; i++)
		num[i] = NULL;
	for (i = 0; i < n; i++)
	{
		b = arr[i];
		a = 0;
		for (k = 0; k < l; k++)//check whether the number is already scanned or not
				{
			d = 0;
			c = num[k];
			d = check(b, c);
			if (d != 0)
			{
				a++;
			}
		}

		if (a == 0)//if number is not already scanned
		{
			c = 0;
			for (j = 0; j < n; j++)//check the array with same numbers 
			{
				if (arr[i] == arr[j])
					c++;
			}

			num[l] = arr[i];
			count[l] = c;
			++l;
		}
	}

	for (i = 0; i < l; i++)
	{
		for (j = i + 1; j < l; j++)
		{
			if (count[i] < count[j])
			{
				a = count[i];
				count[i] = count[j];
				count[j] = a;
				a = num[i];
				num[i] = num[j];
				num[j] = a;
			}
		}
	}
	printf("\n");
	for (i = 0; i < l; i++)
		printf("%d\t", num[i]);
	getch();
}

check(int b, int c)
{
	int k, a = 0;
	if (b == c)
		return 1;
	else
		return 0;
}

- Shouri April 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*it works*/

#include<stdio.h>
#include<conio.h>
main()
{
	int num[100], count[100], arr[100];
	int i, j, k, l = 0, n, a = 0, b, d;
	int c = 0;
	clrscr();
	printf("enter number of elements");
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	for (i = 0; i < 100; i++)
		num[i] = NULL;
	for (i = 0; i < n; i++)
	{
		b = arr[i];
		a = 0;
		for (k = 0; k < l; k++)//check whether the number is already scanned or not
				{
			d = 0;
			c = num[k];
			d = check(b, c);
			if (d != 0)
			{
				a++;
			}
		}

		if (a == 0)//if number is not already scanned
		{
			c = 0;
			for (j = 0; j < n; j++)//check the array with same numbers 
			{
				if (arr[i] == arr[j])
					c++;
			}

			num[l] = arr[i];
			count[l] = c;
			++l;
		}
	}

	for (i = 0; i < l; i++)
	{
		for (j = i + 1; j < l; j++)
		{
			if (count[i] < count[j])
			{
				a = count[i];
				count[i] = count[j];
				count[j] = a;
				a = num[i];
				num[i] = num[j];
				num[j] = a;
			}
		}
	}
	printf("\n");
	for (i = 0; i < l; i++)
		printf("%d\t", num[i]);
	getch();
}

check(int b, int c)
{
	int k, a = 0;
	if (b == c)
		return 1;
	else
		return 0;
}

- Shouri April 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
main()
{
	int num[100], count[100], arr[100];
	int i, j, k, l = 0, n, a = 0, b, d;
	int c = 0;
	clrscr();
	printf("enter number of elements");
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	for (i = 0; i < 100; i++)
		num[i] = NULL;
	for (i = 0; i < n; i++)
	{
		b = arr[i];
		a = 0;
		for (k = 0; k < l; k++)//check whether the number is already scanned or not
				{
			d = 0;
			c = num[k];
			d = check(b, c);
			if (d != 0)
			{
				a++;
			}
		}

		if (a == 0)//if number is not already scanned
		{
			c = 0;
			for (j = 0; j < n; j++)//check the array with same numbers 
			{
				if (arr[i] == arr[j])
					c++;
			}

			num[l] = arr[i];
			count[l] = c;
			++l;
		}
	}

	for (i = 0; i < l; i++)
	{
		for (j = i + 1; j < l; j++)
		{
			if (count[i] < count[j])
			{
				a = count[i];
				count[i] = count[j];
				count[j] = a;
				a = num[i];
				num[i] = num[j];
				num[j] = a;
			}
		}
	}
	printf("\n");
	for (i = 0; i < l; i++)
		printf("%d\t", num[i]);
	getch();
}

check(int b, int c)
{
	int k, a = 0;
	if (b == c)
		return 1;
	else
		return 0;
}

- shourisrinivas April 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Map;
import java.util.HashMap;


public class GetMaxFrequencyNumber {

public static void main(String[] args) {
// TODO Auto-generated method stub

int[] a = {1, 2, 1, 0, 5, 3, 4, 2, 3, 0, 1, 3, 2, 4,3};
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
for (int i = 0; i < a.length; i++) {
if(!map.containsKey(a[i])){
map.put(a[i], 1);
}
else {
System.out.println("value==="+map.get(a[i]));
map.put(a[i], map.get(a[i])+1);
}
}
System.out.println(map);
int maxFrequency =0;
int number = 0;
for (Map.Entry<Integer,Integer> x : map.entrySet()) {
if(x.getValue()>maxFrequency){
maxFrequency = x.getValue();
number = x.getKey();
}
}
System.out.println("Frequency==="+maxFrequency);
System.out.println("Number==="+number);
}
}

- undefined April 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python Implementation :

words = [1, 2, 1, 0, 5, 2, 4, 2, 3, 0, 1, 3, 2, ]
a = {i:words.count(i) for i in set(words)}
print sorted(a , key=a.get,reverse=1)

- Naman April 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python Implementation :

words = [1, 2, 1, 0, 5, 2, 4, 2, 3, 0, 1, 3, 2, ]
a = {i:words.count(i) for i in set(words)}
print sorted(a , key=a.get,reverse=1)

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

Python implementation :

words = [1, 2, 1, 0, 5, 2, 4, 2, 3, 0, 1, 3, 2, ]
a = {i:words.count(i) for i in set(words)}
print sorted(a , key=a.get,reverse=1)

- Naman Dasot April 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

R implementation:

ip <- c(sample(0:5, 15, replace = T))
df <- data.frame(sort(table(ip), decreasing = T)) 
cat(df$ip)

- Anonymous December 15, 2017 | 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