## Skill Subsist Impulse Ltd Interview Question for Data Scientists

• 0

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))
{
}
else
{
maxrepeatnumbers[item]++;
}
}

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

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 } )``````

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)

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])``````

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];}
))``````

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;
}

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")

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"

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)

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;
}``````

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;
}``````

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;
}``````

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);
}
}

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)``````

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)``````

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)``````

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)``````

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.

### 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.